Skip to content

Add Airflow 3.2 in test matrix#2472

Merged
pankajkoti merged 61 commits into
mainfrom
airflow_3.2
Apr 7, 2026
Merged

Add Airflow 3.2 in test matrix#2472
pankajkoti merged 61 commits into
mainfrom
airflow_3.2

Conversation

@pankajastro
Copy link
Copy Markdown
Contributor

@pankajastro pankajastro commented Mar 17, 2026

Add Airflow 3.2 to the Cosmos test matrix and resolve all compatibility issues.

Changes

Airflow 3.2 compatibility

  • Add Airflow 3.2 to the CI test matrix (.github/workflows/test.yml, pyproject.toml)
  • Add pinned requirements-airflow-3.2-dbt-1.11.txt with versions resolved for Python
    3.10 compatibility across all supported Python versions

Import path changes for Airflow 3.2

  • airflow.utils.context.Contextairflow.sdk.definitions.context.Context
  • airflow.utils.context.context_mergeairflow.sdk.definitions.context.context_merge
  • airflow.datasets.DatasetAliasairflow.sdk.definitions.asset.AssetAlias
  • airflow.models.dagbag.DagBag, sync_bag_to_dbairflow.dag_processing.dagbag
  • airflow.configuration.confairflow.providers.common.compat.sdk.conf (per
    Update conf imports in providers to use airflow.sdk.configuration apache/airflow#60000)

All import changes use try/except to maintain backward compatibility with older Airflow
versions.

Other fixes

  • Handle Airflow 3.2 WeightRule API change in TaskInstance creation (tests/conftest.py)
  • Handle SDK AirflowConfigException in cosmos/settings.py (different exception class in
    Airflow 3.2)

closes: #2403


Co-authored-by: Pankaj Koti pankajkoti699@gmail.com

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 98.03922% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.07%. Comparing base (331b90a) to head (402c4e2).

Files with missing lines Patch % Lines
cosmos/__init__.py 95.45% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2472      +/-   ##
==========================================
+ Coverage   97.97%   98.07%   +0.09%     
==========================================
  Files         103      103              
  Lines        7455     7465      +10     
==========================================
+ Hits         7304     7321      +17     
+ Misses        151      144       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

pankajkoti and others added 16 commits April 6, 2026 14:58
…st DAGs

Resolve merge conflicts with main in cosmos/__init__.py (keep lazy
settings import to avoid circular import on Airflow 3.2, use version
from main) and tests/test_example_dags.py (take main's version).

Upgrade Airflow 3.2 from beta2 to rc2 which contains the
ObjectStoragePath credential resolution fix. Remove the redundant
3.2.0b2 special-case in integration-setup.sh.

Remove the Airflow >3.1 .airflowignore entries for
cosmos_manifest_example.py, cosmos_manifest_selectors_example.py,
and cross_project_manifest_dag.py from both test_example_dags.py
and test_example_dags_no_connections.py so these DAGs are tested
in CI again.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Airflow 3.2 changed the initialization order of
airflow.configuration, causing circular imports when providers
import conf from it during startup. The official migration path
(apache/airflow#60000) is to use the compat SDK import instead.

Add type annotations for settings variables used by cache.py
since the compat conf lacks the same type stubs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Airflow 3.2 compat conf raises
airflow.sdk._shared.configuration.exceptions.AirflowConfigException
instead of airflow.exceptions.AirflowConfigException. Catch the SDK
exception class when available.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace eager imports with lazy loading via module-level __getattr__.
Imports are deferred until first access, which:

- Avoids circular imports during Airflow >= 3.2 provider discovery
  where airflow.configuration is not yet fully initialized
- Reduces memory footprint by only loading modules that are used
- Makes the enable_memory_optimised_imports setting unnecessary

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Needed for the cross_project_manifest_dag example DAG.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace multiple uv pip install calls with a single pinned
requirements file for Airflow 3.2, matching the pattern used
by other Airflow versions. Generated via uv pip compile to
ensure dependency consistency.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove numpy, scikit-learn, scipy, pandas, db-dtypes,
google-cloud-aiplatform, networkx, and paradime-io pins that
have Python-version-specific constraints. These are transitive
dependencies resolved differently per Python version.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace rc2 with stable 3.2.0 in requirements and remove the
--prerelease=allow flag from the pre-install script. Regenerate
the requirements file without pre-release packages.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Pin numpy, scikit-learn, scipy, pandas, networkx, paradime-io,
db-dtypes, google-cloud-aiplatform, joblib, and threadpoolctl
using versions resolved for Python 3.10, which are compatible
across all supported Python versions (3.10-3.13).

Also fix RST table alignment in scheduling docs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Comment thread .github/workflows/test.yml Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Apache Airflow 3.2 to the project’s CI/test matrix and updates Cosmos + tests to remain compatible across Airflow 2.x–3.2, mainly by handling Airflow 3.2 import-path and API changes via backward-compatible fallbacks.

Changes:

  • Add Airflow 3.2 to CI/hatch test matrices and add a pinned requirements set for Airflow 3.2 + dbt 1.11.
  • Update Airflow imports (Context/context_merge/DagBag/DatasetAlias/conf) with try/except fallbacks for cross-version compatibility.
  • Adjust tests/utilities to handle Airflow 3.2 TaskInstance/WeightRule differences via a shared helper.

Reviewed changes

Copilot reviewed 21 out of 22 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/utils.py Use new Airflow 3.2 DagBag import path with fallback to legacy location.
tests/operators/test_local.py Switch to shared TaskInstance factory and update Context import for Airflow 3.2+.
tests/operators/test_kubernetes.py Switch to shared TaskInstance factory and update Context import for Airflow 3.2+.
tests/operators/test_gcp_cloud_run_job.py Update Context import for Airflow 3.2+ compatibility.
tests/operators/test_docker.py Update Context import for Airflow 3.2+ compatibility.
tests/operators/test_base.py Update Context import for Airflow 3.2+ compatibility.
tests/operators/test_azure_container_instance.py Update Context import for Airflow 3.2+ compatibility.
tests/operators/test_aws_ecs.py Update Context import for Airflow 3.2+ compatibility.
tests/conftest.py Add make_task_instance helper to handle Airflow 3.2 WeightRule/TaskInstance behavior.
scripts/test/pre-install-airflow.sh Add install branch for Airflow 3.2 pinned requirements.
scripts/test/integration-setup.sh Harden Airflow version parsing and log detected version.
requirements/requirements-airflow-3.2-dbt-1.11.txt Add fully pinned dependency set for Airflow 3.2 + dbt 1.11.
pyproject.toml Add Airflow 3.2 to hatch test matrix.
docs/index.rst Fix indentation in the main docs toctree.
docs/guides/run_dbt/customization/scheduling.rst Adjust table formatting in scheduling guide.
cosmos/settings.py Use compat conf import and handle SDK config exception differences in Airflow 3.2.
cosmos/plugin/airflow3.py Use compat conf import for Airflow 3.2+.
cosmos/operators/kubernetes.py Update context_merge import to Airflow 3.2 SDK location with fallback.
cosmos/operators/base.py Update context_merge import to Airflow 3.2 SDK location with fallback.
cosmos/operators/_asynchronous/bigquery.py Handle DatasetAlias→AssetAlias import move with fallback for older Airflow.
cosmos/init.py Bump package version to 1.14.0a7.
.github/workflows/test.yml Add Airflow 3.2 to CI matrices and adjust workflow push branch trigger.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/operators/test_local.py
Comment thread .github/workflows/test.yml
Fix RST table column alignment in scheduling.rst and fix toctree
indentation in index.rst.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@tatiana tatiana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pankajastro for starting the work, and @pankajkoti for taking it over - Airlfow 3.2.0 was just released, and it will be great to have Cosmos official support to it.

I'm pre-approving the PR, and the merge is subject to the tests passing.

pankajkoti and others added 2 commits April 7, 2026 20:16
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 22 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cosmos/operators/_asynchronous/bigquery.py
Comment thread tests/operators/test_local.py
Add try/except for Context import in bigquery.py and databricks.py
to handle Airflow 3.2 where Context moved to airflow.sdk.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pankajkoti
Copy link
Copy Markdown
Contributor

All tests have passed https://github.com/astronomer/astronomer-cosmos/actions/runs/24088244912?pr=2472 except for the Kubernetes test that appears to be remaining stuck after the merge of PR #2529.

Hence, I am going ahead with the merge.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

_read_target_sources_json,
)
from cosmos.profiles import PostgresUserPasswordProfileMapping
from tests.conftest import make_task_instance
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid importing from tests.conftest in test modules: pytest loads conftest.py as a special plugin module (typically under the name conftest), so importing it as tests.conftest can execute the file a second time under a different module name. Consider moving make_task_instance into a dedicated helper module (e.g., tests/utils_task_instance.py or tests/utils.py) and importing it from there; conftest.py can also import/re-export it if needed.

Suggested change
from tests.conftest import make_task_instance
from conftest import make_task_instance

Copilot uses AI. Check for mistakes.
DbtTestWarningHandler,
)
from cosmos.profiles import PostgresUserPasswordProfileMapping
from tests.conftest import make_task_instance
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid importing from tests.conftest in test modules: pytest loads conftest.py as a special plugin module (typically under the name conftest), so importing it as tests.conftest can execute the file a second time under a different module name. Consider moving make_task_instance into a dedicated helper module (e.g., tests/utils_task_instance.py or tests/utils.py) and importing it from there; conftest.py can also import/re-export it if needed.

Suggested change
from tests.conftest import make_task_instance
from conftest import make_task_instance

Copilot uses AI. Check for mistakes.
@pankajastro pankajastro mentioned this pull request Apr 7, 2026
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.

Add support to Airflow 3.2.0

4 participants