Upgrade SQLAlchemy from 1.4 to 2.0#272
Open
kaapstorm wants to merge 16 commits into
Open
Conversation
jingcheng16
previously approved these changes
May 4, 2026
Contributor
jingcheng16
left a comment
There was a problem hiding this comment.
I know nothing about SQLAlchemy, so I just reviewed and make sure the code changes follow the commit messages. Can approve again when conflicts are resolved.
Remove MetaData(bind=...), autoload=True, declarative_base() import, and branched-connection pattern in env.py. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
IntegrityError handling no longer aborts the outer transaction. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Raw SQL strings must be wrapped in text() in SQLAlchemy 2.0. Also convert positional %s parameters to named :name bindings, and add conn.commit() calls after DDL operations now that autocommit has been removed.
engine.execute() was removed in SQLAlchemy 2.0. Callers must obtain a connection via engine.connect() and execute statements on it.
In SQLAlchemy 2.0 rows are tuple-like by default. Call .mappings() on the Result to iterate dict-like RowMapping objects.
Accessing the raw DB-API connection via Connection.connection.connection is deprecated in SQLAlchemy 2.0. Use Connection.connection.dbapi_connection instead.
93a3333 to
8c0844e
Compare
Replace raw SQL COMMIT with SQLAlchemy 2.0 transaction API: - __enter__/__exit__ manage begin/commit/rollback - _flush() commits current transaction and starts a new one - _flush_batch() rolls back failed transaction before retry Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
SQLAlchemy 2.0's .mappings() returns RowMapping dicts, not tuples. Update assertions to compare against dicts with column names as keys. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Annotate compatibility dict in writers.py to accept dialect-specific types like JSON and BIT - Use separate variable names for postgres and mysql insert statements to avoid type conflicts - Remove unused type: ignore comment from Checkpoint class - Cast pagination_mode to str for enum indexing - Assert dbapi_connection is not None before accessing autocommit Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Please excuse the rebase + force pushes. I think it makes for easier reviewing than a merge with a bunch of fixes. |
Contributor
|
@kaapstorm Is this just a rebase because the base branch changed? Or is there any new commits that requires review? |
Contributor
Author
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.
This branch upgrades SQLAlchemy from 1.4 to 2.0. This is required by the changes in PR #269 for the transaction management introduced in SQLAlchemy 2.0.
Each commit is small, or covers a small change across many files. Automated changes by ruff are in their own commits.