-
Notifications
You must be signed in to change notification settings - Fork 297
Centralize version-aware EmptyOperator imports in a compatibility module #2758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5324482
Use a version-aware EmptyOperator import path via a shared constant
pankajkoti fe4c60d
Centralize version-aware EmptyOperator imports in a compatibility module
pankajkoti 93b8b57
Compare on Airflow major version and cache lazy imports
pankajkoti b91b95f
Resolve EmptyOperator via a direct version-aware import
pankajkoti c0830b2
Exclude the unreachable provider-missing guard from coverage
pankajkoti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| """Version-aware imports for Airflow objects whose import path differs across Airflow 2 and 3. | ||
|
|
||
| ``EmptyOperator`` moved to the standard provider in Airflow 3; the legacy | ||
| ``airflow.operators.empty`` path still resolves there but emits a ``DeprecatedImportWarning``, | ||
| so on Airflow 3 we import it from the standard provider. Compare on the major version so that | ||
| Airflow 3 pre-releases (e.g. 3.0.0rc1) are treated as Airflow 3. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from cosmos.constants import _AIRFLOW3_MAJOR_VERSION, AIRFLOW_VERSION | ||
|
|
||
| if AIRFLOW_VERSION.major >= _AIRFLOW3_MAJOR_VERSION: | ||
| try: | ||
| from airflow.providers.standard.operators.empty import EmptyOperator as EmptyOperator | ||
| except ImportError as exc: # pragma: no cover | ||
| raise ImportError( | ||
| "Cosmos on Airflow 3 requires `apache-airflow-providers-standard` to import `EmptyOperator`." | ||
| ) from exc | ||
| else: | ||
| # The redundant ``as EmptyOperator`` alias marks the name as an explicit re-export for type | ||
| # checkers; the ``no-redef`` ignore silences the duplicate binding mypy sees across branches. | ||
| from airflow.operators.empty import EmptyOperator as EmptyOperator # type: ignore[no-redef] | ||
|
|
||
| # Dotted import path for the version-appropriate EmptyOperator, for the places that store the | ||
| # operator as a string for later dynamic import (e.g. ``Task.operator_class``) rather than | ||
| # referencing the class. Derived from the class itself, so it always matches the imported one. | ||
| EMPTY_OPERATOR_CLASS_PATH = f"{EmptyOperator.__module__}.{EmptyOperator.__name__}" | ||
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.