Repository navigation
Support SQLAlchemy 2.1 type hints - #77494
Merged
uranusjr merged 2 commits intoNov 25, 2026
Merged
Conversation
uranusjr
requested review from
XD-DENG,
amoghrajesh,
ashb,
bugraoz93,
choo121600,
ephraimbuddy,
gopidesupavan,
henry3260,
hussein-awala,
jason810496,
jedcunningham,
jscheffl,
pierrejeambrun,
potiuk,
shubhamraj-git and
vatsrahul1001
as code owners
November 23, 2026 13:23
vincbeck
approved these changes
Nov 23, 2026
Collaborator
|
SQLAlchemy 2.1 changed the type definition in a backward incompatible way, causing Mypy issues with the existing code base (runtime support does not break, only type hints). The new types should be the way going forward, but unfortunately 2.1 does not support Python 3.13 and lower, and some of the Airflow providers do not yet support 3.14. To work around the issue, a small shim is implemented in Airflow with a small plugin to switch behavior between the two distinct combinations. Once Python 3.14 is supported across the board, we can simply remove the plugin and change the type imports without needing to fix any of the type hints. While applying the shim, issues were discovered in LazySelectSequence. After further inspection, the offending code was leftover from Airflow 2 that has been dead for quite a while and no longer needed. It doesn't work if explicitly called anyway (reflected by the now-correct type hints), and therefore has been removed entirely.
uranusjr
force-pushed
the
claude/mypy-sqlalchemy-handoff-6fd4d2
branch
from
November 23, 2026 22:17
8f483c6 to
14a196a
Compare
uranusjr
enabled auto-merge (squash)
November 23, 2026 22:17
Member
Author
|
CI failures being fixed in #77535 |
ephraimbuddy
approved these changes
Nov 24, 2026
Contributor
Backport failed to create: v3-4-test. View the failure log Run detailsNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
You can attempt to backport this manually by running: cherry_picker c70a5ed v3-4-testThis should apply the commit to the v3-4-test branch and leave the commit in conflict state marking After you have resolved the conflicts, you can continue the backport process by running: cherry_picker --continueIf you don't have cherry-picker installed, see the installation guide. |
1 task done
Lee-W
added a commit
to astronomer/airflow
that referenced
this pull request
Nov 25, 2026
Since apache#77494 the type checker sees a single-column select as Select[int], so the Select[tuple[int]] annotations no longer matched what the callers pass.
Lee-W
added a commit
to viiccwen/airflow
that referenced
this pull request
Nov 26, 2026
Since apache#77494 the type checker sees a single-column select as Select[int], so the Select[tuple[int]] annotations no longer matched what the callers pass.
Lee-W
added a commit
to viiccwen/airflow
that referenced
this pull request
Nov 27, 2026
Since apache#77494 the type checker sees a single-column select as Select[int], so the Select[tuple[int]] annotations no longer matched what the callers pass.
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.
SQLAlchemy 2.1 changed how
Selectis parameterised: 2.0 takes the row tuple (Select[tuple[X, Y]]), while 2.1 takes the column types (Select[X, Y]). Runtime behaviour is unaffected, but each spelling is wrong for mypy under the other version. Since #76705,uv.lockresolves SQLAlchemy 2.1 only on Python 3.14+ (the Snowflake provider still caps it below 2.1 elsewhere, #75118), so local mypy runs on Python 3.14 failed while CI stayed green.To work around this, a small
Selectshim is added for type checking only, together with a mypy plugin that tells mypy which SQLAlchemy is installed. Annotations are written the 2.1 way and type-check precisely on both versions. Once the lock resolves 2.1 everywhere, the plugin can be removed and the shim replaced with a plainsqlalchemy.sql.Selectimport, without touching the annotations.While applying the shim, issues were found in
LazySelectSequence. Its pickling support was left over from Airflow 2 (#28191, for@task.virtualenv) and has been unused for a while. It also didn't work: an unpickled sequence never got its session back, and its rebuilt statement couldn't be indexed or sliced. So it's removed rather than fixed, and pickling now raisesTypeError. The class is also unhashable now, like a list.Pool.slots_statsnow skips pool rows with no name, which SQLAlchemy 2.1's stricter types surfaced.related: #76705, #75118