Fix SQLAlchemy 2.0 compatibility issues for Invenio upgrade #911
+6
−4
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 PR addresses SQLAlchemy 2.0 compatibility issues to prepare for upgrading Invenio packages that require
SQLAlchemy>=2.0.0. The changes ensure the codebase works with both SQLAlchemy 1.4 and 2.0 by following the official migration guide.Key Changes
String SQL Query Execution
SQLAlchemy 2.0 requires string-based SQL queries to be wrapped with the
text()function. Updated:hepdata/cli.py): Wrapped SQL query parameter withtext()hepdata/modules/records/utils/data_files.py): Wrapped complex multi-line SQL withtext()and added necessary importSyntax Warning Fix
Fixed invalid escape sequence in regex pattern (
hepdata/ext/opensearch/query_builder.py) by using raw string literal to eliminate Python deprecation warnings.Compatibility
These changes maintain full backwards compatibility with SQLAlchemy 1.4 while ensuring forward compatibility with 2.0. The existing
db.select()patterns and result iteration methods are already 2.0-compatible and require no changes.Testing
Validated that:
SQLALCHEMY_WARN_20=1enabledWith these minimal surgical changes, the repository is ready for the Invenio package upgrades that require SQLAlchemy 2.0.
Fixes #848.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.