Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLAlchemy 2.0: Restore backward-compatibility with SQLAlchemy 1.3 #497

Merged
merged 2 commits into from
Dec 23, 2022

Conversation

amotl
Copy link
Member

@amotl amotl commented Dec 23, 2022

About

Compatibility module for running a subset of SQLAlchemy 2.0 programs on SQLAlchemy 1.3. By using monkey-patching, it can do two things:

  1. Add the exec_driver_sql() method to SQLAlchemy's Connection and Engine, forwarding to execute().
  2. Amend the sql.select() function to accept the calling semantics of the modern variant.

Reason

After modernizing the code base, exec_driver_sql now is used within the CrateDB dialect, and the new calling semantics of sql.select are used within many of the test cases already.

Notes

Please note that the patch for sql.select is only applied when running the test suite.

References

Resolve import of `declarative_base`. For SA13, it is in
`sqlalchemy.ext.declarative`, while it is in `sqlalchemy.orm` on more
recent versions of SA.
@amotl amotl marked this pull request as ready for review December 23, 2022 23:05
Note that this is on a best-effort basis. SQLAlchemy 2.0 will be
mostly compatible with most SQLAlchemy 1.3 code which is not using any
of the deprecated functionalities, modulo a few aspects.

> It is possible to have code that is compatible with 2.0 and 1.3 at the
> same time, you would just need to ensure you use the subset of
> features and APIs that are common to both.

This patch adds a small compatibility layer, which activates on SA13
only, and monkey-patches two spots where anomalies have been spotted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQLAlchemy: Maintenance support for SQLAlchemy 1.3
1 participant