Skip to content

Fix mypy errors from SQLAlchemy 2.1 typing in fab sorting and standard sensor_helper - #75075

Merged
vincbeck merged 1 commit into
apache:mainfrom
astronomer:fix-sqlalchemy-mypy-typing
Oct 19, 2026
Merged

vincbeck merged 1 commit into
apache:mainfrom
astronomer:fix-sqlalchemy-mypy-typing

Conversation

@Lee-W

@Lee-W Lee-W commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Why

SQLAlchemy 2.1 changed how some constructs are typed, which makes mypy fail on the providers as soon as the resolved version moves past the one pinned in uv.lock (2.0.54). The fixes below type-check on both versions, so CI stays green on the locked version and the failures do not appear when 2.1 is picked up.

What

  • desc(col) now returns OrderByList | UnaryExpression, which is not a ColumnElement. The col.desc() / col.asc() method form still returns a ColumnElement, so the fab build_ordering helper and its callers keep their existing annotations. The generated ORDER BY is the same.
  • select(func.count()) is inferred as Select[tuple[int]] on 2.0 but Select[int] on 2.1, and session.scalar() is typed accordingly. No single concrete annotation or cast passes on both versions (cast is flagged redundant-cast on 2.0). The statement and the session.scalar() result are therefore routed through Any in one place (_count_stmt and a small _get_scalar_count helper) instead of silencing each call site. The compiled SQL is unchanged.

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: [Claude] following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

…d sensor_helper

Use Column.asc()/desc() in fab build_ordering and make the sensor_helper count helpers type-check on both SQLAlchemy 2.0 and 2.1.
@Lee-W
Lee-W force-pushed the fix-sqlalchemy-mypy-typing branch from d260fb4 to beb1983 Compare October 19, 2026 09:27
@Lee-W
Lee-W marked this pull request as ready for review October 19, 2026 09:33
@Lee-W
Lee-W requested a review from vincbeck as a code owner October 19, 2026 09:33
@vincbeck
vincbeck merged commit 5ce21c5 into apache:main Oct 19, 2026
173 of 184 checks passed
@Lee-W
Lee-W deleted the fix-sqlalchemy-mypy-typing branch November 9, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants