Skip to content

Sqlalchemy 2 migration - Fix MyPy type errors in core Airflow #56735

Closed

Description

@vincbeck

Apache Airflow version

3.1.0

If "Other Airflow 2/3 version" selected, which one?

No response

What happened?

Summary

This issue tracks the resolution of MyPy type errors found in the Airflow core codebase when SQLA 2 is used.
There are currently 525 errors across 100 files that need to be addressed before being able to upgrade to SQLA2.
Also, this will improve type safety and code quality.

How to generate the errors

  • Apply changes from Remove SQLA 1 limit in Fab provider #56212 locally

  • Run breeze ci-image build --python 3.10 --upgrade-to-newer-dependencies

  • Run prek --color always --verbose --hook-stage manual "mypy-airflow-core" --all-files reveals numerous type errors throughout the codebase. These errors primarily involve:

    • Incompatible type assignments (datetime vs UtcDateTime)
    • Missing type annotations
    • Union type handling issues
    • SQLAlchemy ORM type mismatches
    • Return value type inconsistencies

Current Status (Updated: 2025-11-24)

Total errors found: 24 errors in 8 files (checked 1021 source files)

Error Breakdown by Directory

airflow-core/src/airflow/models/ (13 errors in 4 files)

  • connection.py (1 error)
  • taskmap.py (4 errors)
  • dag.py (2 errors)
  • serialized_dag.py (6 errors)

airflow-core/src/airflow/ti_deps/deps/ (10 errors in 1 file)

  • trigger_rule_dep.py (10 errors)

airflow-core/src/airflow/api_fastapi/common/db/ (1 error in 1 file)

  • dag_runs.py (1 error)

airflow-core/src/airflow/api_fastapi/execution_api/routes/ (2 errors in 1 file)

  • task_instances.py (2 errors)

airflow-core/src/airflow/api_fastapi/core_api/routes/ui/ (1 error in 1 file)

  • dags.py (1 error)

How to Contribute

  1. Pick a file: Choose an unchecked file from the list above
  2. Check the box: Update this issue to mark the file as being worked on
  3. Run MyPy locally: Follow the steps mentioned above to generate the errors. You can also run prek mypy-airflow-core --directory <directory> to run mypy in the directory you are working on
  4. Fix the errors: Address the type errors in your chosen file
  5. Test your changes: Ensure tests still pass
  6. Submit a PR: Create a pull request with your fixes. Please do not include in your PR changes from Remove SQLA 1 limit in Fab provider #56212

Guidelines

  • Focus on one file or directory at a time
  • Follow existing code patterns and conventions

Let's work together to improve Airflow's type safety! 🚀

Note: This issue was generated by running MyPy on the current codebase. The error counts may change as the codebase evolves.

What you think should happen instead?

No response

How to reproduce

  • Apply changes from Remove SQLA 1 limit in Fab provider #56212 locally
  • Run breeze ci-image build --python 3.10 --upgrade-to-newer-dependencies
  • Run prek --color always --verbose --hook-stage manual "mypy-airflow-core" --all-files reveals numerous type errors throughout the codebase

Operating System

Macos

Versions of Apache Airflow Providers

No response

Deployment

Other

Deployment details

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    kind:meta
    and removed
    needs-triage
    kind:bug
    on Oct 16, 2025
  2. Jonpaco23 commented on Oct 20, 2025

    @Jonpaco23
    Contributor

    Hello, first time contributer. Gonna give these a try: api_fastapi/core_api/routes/ui/*

  3. vincbeck commented on Oct 21, 2025

    @vincbeck
    ContributorAuthor

    I updated the issue. 339 errors to go 🚀

  4. sanju1198 commented on Oct 23, 2025

    @sanju1198
    Contributor

    Hi, first-time contributor. I'd like to try fixing the MyPy error in airflow/models/variable.py

  5. vincbeck commented on Oct 23, 2025

    @vincbeck
    ContributorAuthor

    Hi, first-time contributor. I'd like to try fixing the MyPy error in airflow/models/variable.py

    Please do :)

  6. chiuinggum commented on Oct 25, 2025

    @chiuinggum
    Contributor

    Hi, I'd like to fix airflow-core/tests/unit/api_fastapi/core_api/routes/public/

  7. 17 remaining items

  8. vincbeck commented on Nov 7, 2025

    @vincbeck
    ContributorAuthor

    Issue updated

  9. profgrammer commented on Nov 8, 2025

    @profgrammer
    Contributor

    Working on airflow-core/src/airflow/models/xcom.py

    Seems like the previous piece I was working on is solved already.

  10. KoviAnusha commented on Nov 8, 2025

    @KoviAnusha
    Contributor

    Working on airflow-core/src/airflow/models/xcom.py

    I was already working on this one (#57532)

  11. profgrammer commented on Nov 9, 2025

    @profgrammer
    Contributor

    Working on airflow-core/src/airflow/api/common/delete_dag.py if it's still available.

  12. profgrammer commented on Nov 10, 2025

    @profgrammer
    Contributor

    working on airflow-core/src/airflow/jobs/scheduler_job_runner.py

  13. Srabasti commented on Nov 13, 2025

    @Srabasti
    Contributor

    While trying to understand the changes needed to replicate the issue, I see that the "How to Contribute" section 6 mentions "not" to include changes from #56212

    Image

    This is contradicting with the section "How to reproduce" that says to "Apply changes from #56212 locally" as below.

    Image

    Can someone please share the correct steps to replicate, since both these 2 different statements are contradicting each other?

  14. Prab-27 commented on Nov 13, 2025

    @Prab-27
    Contributor

    @Srabasti ,
    As I understand , This PR #56212 removes the SQLAlchemy 1 limit. After applying these changes, run:
    breeze ci-image build --python 3.10 --upgrade-to-newer-dependencies
    At this stage, you're no longer using SQLAlchemy 1.x.
    You’ll be able to reproduce the mypy errors introduced by that PR. Fix those errors here, and once resolved, you can remove the changes from that PR.

    You're essentially fixing the mypy issues that came from that PR

    If you’d like to discuss anything while working on this, there’s a Slack channel: #fab-upgrade.

  15. arnoldmr01 commented on Nov 18, 2025

    @arnoldmr01
    Contributor

    Working on airflow-core/src/airflow/models
    dag.py
    dag_bag.py

  16. KoviAnusha commented on Nov 19, 2025

    @KoviAnusha
    Contributor

    Working on airflow-core/src/airflow/models dag.py dag_bag.py

    Sorry but I already have an open PR for that #57532

  17. arnoldmr01 commented on Nov 20, 2025

    @arnoldmr01
    Contributor

    Will start working on airflow-core/src/airflow/models/
    taskmap.py
    serialized_dag.py

  18. henry3260 commented on Nov 20, 2025

    @henry3260
    Member

    Will start working on airflow-core/src/airflow/models/ taskmap.py serialized_dag.py

    I already work on taskmap.py in #57862 .

  19. KoviAnusha commented on Nov 22, 2025

    @KoviAnusha
    Contributor

    Will start working on airflow-core/src/airflow/models/ taskmap.py serialized_dag.py

    I am already working on serialized_dag #58062

  20. vincbeck commented on Nov 24, 2025

    @vincbeck
    ContributorAuthor

    Issue updated! 24 errors to go :)

  21. vincbeck commented on Jan 5, 2026

    @vincbeck
    ContributorAuthor

    Completed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coregood first issuekind:meta

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions