Skip to content
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

Add compat module for typing execute context in operators #770

Merged
merged 4 commits into from
Sep 12, 2022

Conversation

josh-fell
Copy link
Contributor

@josh-fell josh-fell commented Sep 3, 2022

Closes: #769

Description

What is the current behavior?

The airflow.utils.context module was not introduced to OSS Airflow until 2.2.3. Importing this module as a top-level import sets an implicit, minimum requirement for Airflow 2.2.3 which is higher than the minimum apache-airflow requirement set for Astro SDK.

What is the new behavior?

  • This PR adds a typing compat module to be used throughout the repo for consistent typing of context in operators.

Does this introduce a breaking change?

It should not.

Checklist

  • Created tests which fail without the change (if possible)
  • Extended the README / documentation, if necessary


from astro.files.base import File
from astro.files.locations import create_file_location

if TYPE_CHECKING:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

@josh-fell & @kaxil I like @kaxil 's proposal of having a compatibility module.
It would also be nice to see tests covering this issue - since we are using nox, it should be straightforward to add a test.

Copy link
Contributor Author

@josh-fell josh-fell Sep 6, 2022

Choose a reason for hiding this comment

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

Absolutely, great idea! I'll add a compat module and unify the type across the repo, where applicable. And some tests too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, any preference on having a pre-commit hook to check that the typing compat module is used vs. a unit test?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Either is fine :)

@@ -18,6 +17,10 @@
from astro.sql.operators.load_file import LoadFileOperator
from astro.sql.table import Table

if TYPE_CHECKING:
# TODO: This can be removed from TYPE_CHECKING once there is a minimum requirement of Airflow 2.2.3+
from airflow.utils.context import Context
Copy link
Member

Choose a reason for hiding this comment

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

Let's make sure to change to "Context" in all places of the current file as you have done it for the other file.

@kaxil kaxil added this to the 1.1.0 milestone Sep 6, 2022
@josh-fell josh-fell marked this pull request as draft September 7, 2022 03:36
@josh-fell
Copy link
Contributor Author

Added a pre-commit hook along with a typing_compat module in 68e8522.

@josh-fell josh-fell changed the title Move airflow.utils.context.Context import under TYPE_CHECKING Add compat module for typing execute context in operators Sep 9, 2022
@josh-fell josh-fell marked this pull request as ready for review September 9, 2022 21:18
@kaxil kaxil added the safe to test Adding this label to a PR, will allow running all the tests in CI. (use it with caution) label Sep 9, 2022
@josh-fell
Copy link
Contributor Author

josh-fell commented Sep 12, 2022

Actually, since this repo implements PEP563 typing evaluations, we could still use TYPE_CHECKING with airflow.utils.context.Context and not have to use a stringified type annotation for Context. Then, when this repo has a minimum Airflow requirement of at least 2.2.3, it's only a matter of removing the TYPE_CHECKING rather than removing the compat module, the pre-commit hook, and changing all of the imports.

Just another option to consider and I'll defer to the group on maintenance preference. Trivial updates either way I suppose.

josh-fell and others added 4 commits September 12, 2022 12:51
The `airflow.utils.context` module was not introduced to OSS Airflow until 2.2.3. Importing this module as a top-level import sets an implicit, minimum requirement for Airflow 2.2.3 which is higher than the minumum apache-airflow requirement set for Astro SDK.
@kaxil kaxil merged commit 7abcda8 into astronomer:main Sep 12, 2022
@josh-fell josh-fell deleted the context branch September 13, 2022 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test Adding this label to a PR, will allow running all the tests in CI. (use it with caution)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot use cleanup when running Airflow <2.2.3 due to airflow.utils.context import error
4 participants