Replies: 8 comments 20 replies
|
This is great, thanks for working on this! |
|
@hy144328 what's the next step (or steps) here? Happy to help move things forward, we just might be able to land this in 7.0 if we're quick :D |
|
Didn't want to wait on this, so I dug into the actual checklist (the commented-out As it turns out, that env var is never actually set anywhere in CI, so none of this, including the 3 categories already "locked in", has ever been enforced automatically. #41915 fixes that. Also tried to knock out a few more categories that looked like free wins from a quick grep, but two of them ( @hy144328 does this line up with what you had in mind, or do you already have more of this in flight? Don't want to step on toes. |
|
THANK YOU VERY MUCH for doing this!! I'm a huge fan and a heavy user of Superset at my firm. However, IT dept is threatening to shut it down due to Superset's pin on Python 3.11, which only has 1 year left before reaching End Of Life. Apparently, being able to receive security patches is a big deal at my firm, and I'm sure many firms are in the same shoe. Apparently, the pin on 3.11 was mainly due to SqlAlchemy. So your work to bump SqlAlchemy to 2.0 is life-saving!!! |
|
Chipped away at three more of the cascade_backrefs cases: Query (#42210), SavedQuery (#42212), and SqlaTable (#42213). Turns out the callers were already adding everything to the session explicitly, so each one is just |
|
Maybe we should also add an item to the TODO list to bump all the SQLAlchemy drivers to the newer 2.0 compatible versions. It's basically follow-up work, but we might as well enumerate it. |
|
Approved #42277 but not sure if you want to fix the nit there before I merge it. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I would like to propose a plan to migrate from SQLAlchemy 1.4 to 2.0.
From what I see in discussions, issues and PRs, we have not quite hit the homerun yet.
I already have some PRs in preparation, and I am interested in feedback.
Goals
Motivation
Personal motivation:
My company uses Superset with Dremio.
The SQLAlchemy plug-in for Dremio requires SQLAlchemy 2. https://github.com/narendrans/sqlalchemy_dremio/blob/c576c65318f58e9342bbdb3dd0d6d691af9299ba/setup.py#L12
Superset is still stuck at SQLAlchemy 1.
superset/pyproject.toml
Line 102 in 1230b90
Currently, we use a fork that forcefully downgrades the SQLAlchemy plug-in for Dremio.
However, this is not sustainable in the long term.
General motivation:
While SQLAlchemy has no official EOL dates, it is virtually there. sqlalchemy/sqlalchemy#13009
SQLAlchemy 2.0 has been out for multiple years now.
SQLAlchemy 2.1 is around the corner.
This will make SQLAlchemy obsolete.
Observations
SQLAlchemy 1.4 to 2.0 is a breaking change.
This includes both the direct dependency on SQLAlchemy and the indirect dependencies on other packages, e.g. Flask and Flask-SQLAlchemy.
There is a single-shot PR by @dpgaspar that attempts to bump everything in a single PR.
I am not sure whether the PR is ready.
The last commit is from September 2025.
The PR touches 92 files and over a thousand lines of code, which makes it a daunting task to review.
Therefore, I would like to suggest smaller steps to some pressure off before the final push of bumping the dependencies.
Firstly, SQLAlchemy 1.4 (current version) is already designed to be a transition version. https://docs.sqlalchemy.org/en/20/changelog/migration_20.html#the-1-4-2-0-migration-path
This means that it enables in many cases both version 1 and 2 styles.
So we are able to update the code without actually bumping the SQLAlchemy version.
Secondly, SQLAlchemy is able to emit warnings.
This way, we are able to use the existing unit tests to check on the progress of the migration.
Thirdly, Python
warningsand PyTest integrate well with each other.So we are able to turn warning into errors, and mitigate regressions during collaboration.
Battleplan
Enable SQLAlchemy 1.4 deprecation warning in unit testing set-up.
After running all unit tests, I get the following warning cases:
This means that we are able to work on each warning case more or less independently:
as_declarative()function is now available chore: as_declarative() warnings are irrelevant #41982databasepackage is deprecated chore: sqlalchemy.database package warnings are irrelevant #41978declarative_base()function is now available refactor: import from sqlalchemy.orm #41981Use the
futureflag onEngine. https://docs.sqlalchemy.org/en/20/changelog/migration_20.html#migration-to-2-0-step-four-use-the-future-flag-on-engine refactor: engine enforce SQLAlchemy 2.0 #42277Use the
futureflag onSession. https://docs.sqlalchemy.org/en/20/changelog/migration_20.html#migration-to-2-0-step-five-use-the-future-flag-on-session chore: session enforce sqlalchemy 2.0 #42365Add
__allow_unmapped__to explicity typed ORM models. https://docs.sqlalchemy.org/en/20/changelog/migration_20.html#migration-to-2-0-step-six-add-allow-unmapped-to-explicitly-typed-orm-models refactor: make import/expression layer SQLAlchemy 2.0-compatible #41179Actually bump SQLAlchemy and indirect dependencies.
By then, chore: Support Flask 3.X and SQLAlchemy 2.X #35117 will hopefully have to do some less heavy lifting. :-)
Clean up the unit test set-up again.
Conclusion
As mentioned, I already have some PRs in mind, that I will add to the battleplan.
I do not see any downsides to the refactoring approach of incrementally mitigating the deprecation warnings before the actual bump (except boredom).
Curious to hear your thoughts.
All reactions