Repository navigation
Support SQLAlchemy 2.0 alongside 1.4 - #284
Open
xravitycapital wants to merge 1 commit into
Open
xravitycapital wants to merge 1 commit into
xravitycapital wants to merge 1 commit into
Conversation
Widen the pin to sqlalchemy>=1.4.53,<2.1, import declarative_base from sqlalchemy.orm, set __allow_unmapped__ on Base so existing Column annotations keep working on 2.0, annotate the creator_id/creator declared_attrs with Mapped[...], and run the tests on 2.0 in CI. Closes dynotx#205 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #205
Thanks @steve-dyno for the update on the issue. Since Dyno is looking at SQLAlchemy 2 again, I thought a concrete PR might be easier to evaluate than a description. No pressure on timing: if it's not the right moment, or you'd rather take a different approach, I'm happy to adjust it or close it.
Why
Projects that depend on SQLAlchemy 2.x (for example through
fastapi-users-db-sqlalchemy) can't install liminal-orm because it pinssqlalchemy<2. This keeps 1.4 fully supported, so anyone still on 1.x isn't affected, and also allows 2.0.x. Teams can then upgrade SQLAlchemy whenever they're ready.Changes
pyproject.toml:sqlalchemy>=1.4.53,<2.1. The dev group still pins1.4.53, so the locked environment is unchanged.liminal/orm/base.py:declarative_basefromsqlalchemy.orm. It's available since 1.4, and theext.declarativeimport is deprecated in 2.0.__allow_unmapped__ = TrueonBase. With it, 2.0 accepts existingcol: SqlColumn = Column(...)annotations, including those in generated model files. 1.4 ignores this attribute.liminal/orm/base_model.pyandliminal/orm/base_results_model.py: annotatecreator_idasMapped[str | None]andcreatorasMapped[Any]. 2.0 requiresMapped[]return annotations on@declared_attr, and__allow_unmapped__doesn't cover them..github/workflows/cicd.yml: add a step that also runs the tests on SQLAlchemy 2.0, viauv run --with "sqlalchemy>=2.0,<2.1".Testing
pre-commit(ruff, ruff-format, mypy) passes on the changed files.Notes for reviewers
session.query(...)andconnection().execute(query.statement), and 2.0 still supports both.engine.execute. That's outside this PR, but it might be worth a line in the release notes.About me
To be upfront: I used an AI coding assistant for this, and I reviewed and tested every change myself. I'm also trying to build a small paid service around this kind of work, partly to earn some extra money for my family. This PR is completely free, though, with nothing expected in return. I just hope it's useful. Sorry if this is an unwelcome interruption.
🤖 Generated with Claude Code