Skip to content

Conversation

@potiuk
Copy link
Member

@potiuk potiuk commented Nov 28, 2025

Since we are quite close to having a completed separation between
distributions, this PR will be rebased until we will fix all the
issues - we might want to extract things from this PR as we
rebase it and move the code between distributions.

The following checks were added:

  • The shared distributions (neither in src nor tests) should never
    import from airflow.

  • The distributions that are using shared code "airlfow-core",
    "task-sdk" should never import anything from either
    "airflow_shared" or from "_shared" import coming from another
    distribution.

  • Neither "apache-airflow", "apache-airflow-task-sdk", "apache-airflow-core"
    should be added as dependency in a shared distribution.

  • The "devel-common" should also not refer to airflow.* - it should only
    import from airflow_shared.*


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@boring-cyborg boring-cyborg bot added area:dev-tools backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch labels Nov 28, 2025
@potiuk potiuk force-pushed the add-prek-hook-for-airflow-imports-in-shared branch 2 times, most recently from ee1c3ca to 915a85f Compare November 28, 2025 18:09
Copy link
Contributor

@jscheffl jscheffl left a comment

Choose a reason for hiding this comment

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

Cool!

@potiuk potiuk added the full tests needed We need to run full set of tests for this PR to merge label Nov 28, 2025
@potiuk potiuk force-pushed the add-prek-hook-for-airflow-imports-in-shared branch from 915a85f to 90412d0 Compare November 28, 2025 23:14
@potiuk
Copy link
Member Author

potiuk commented Nov 28, 2025

Small thing - this one should fail. I restarted it with full-tests-needed.

@potiuk potiuk removed the full tests needed We need to run full set of tests for this PR to merge label Nov 28, 2025
@potiuk potiuk force-pushed the add-prek-hook-for-airflow-imports-in-shared branch from 90412d0 to 7e2ba2e Compare November 28, 2025 23:20
@potiuk
Copy link
Member Author

potiuk commented Nov 28, 2025

OK. Figured out why it did not run - added "scripts/ci/prek" to also trigger full tests.

@potiuk potiuk force-pushed the add-prek-hook-for-airflow-imports-in-shared branch 2 times, most recently from 0b0881d to b537ffe Compare November 29, 2025 12:57
@potiuk potiuk force-pushed the add-prek-hook-for-airflow-imports-in-shared branch from b537ffe to 79426a7 Compare November 29, 2025 13:01
@potiuk
Copy link
Member Author

potiuk commented Nov 29, 2025

@amoghrajesh @xBis7 - I solved the "module_loading" import issue (I created a new shared distribution "import_utils") and added even more checks in the prek hook. It nicely shows now all the remaining issues that we have to solve (basically settings that already had some TODOs and issues).

I will keep on extracting things from this PR to separate PRs (for example extraction of import_utils can be done as a separate PR) - and I think that might be a good idea for other changes - to rebase them on top of this one, because this one immediately shows now violations of imports that we still have :)

@potiuk potiuk changed the title Add prek hook to check for "airflow" imports in shared distributions Improve prek hook to check for proper imports in shared distributions Nov 29, 2025
@potiuk
Copy link
Member Author

potiuk commented Nov 29, 2025

And IMMEDIATELY we got benefit of the common.compat # use next version detection @jscheffl @vincbeck !!!!!!

Screenshot 2025-11-29 at 14 04 48

@potiuk potiuk force-pushed the add-prek-hook-for-airflow-imports-in-shared branch 2 times, most recently from b9d66dc to 8de0d2a Compare November 29, 2025 13:53
@potiuk potiuk force-pushed the add-prek-hook-for-airflow-imports-in-shared branch 4 times, most recently from 17fa532 to e52d2e0 Compare December 1, 2025 21:13
@potiuk
Copy link
Member Author

potiuk commented Dec 1, 2025

@amoghrajesh @xBis7 I rebased my change and added some changes:

  • the "import_utils.module_loading" module is no longer "import_utils" - it's just module_loading - I modified the code quite a bit to move the shared methods to __int__.py rather than have a "import_utls.module_loading` - i think that can largely alleviate those concerns @amoghrajesh had about too many "utils" - I think it's really nice one and simpler than before.

  • I also realised we need one more check (and turned out we have quite a bit of work to do still). The devel-common module needs a bit of polish, refactor - and I think we will have to add all the_shared modules as dependencies to it. Simply devel_common should NEVER import anything from airflow. nor airflow.sdk - because it can be use in either of the two (and other disstributions) - so it should import everything from airflow_shared.* and have those packages it imports from as dependencies.

@potiuk potiuk force-pushed the add-prek-hook-for-airflow-imports-in-shared branch from e52d2e0 to 5b99a82 Compare December 1, 2025 22:17
@amoghrajesh
Copy link
Contributor

I also realised we need one more check (and turned out we have quite a bit of work to do still). The devel-common module needs a bit of polish, refactor - and I think we will have to add all the_shared modules as dependencies to it. Simply devel_common should NEVER import anything from airflow. nor airflow.sdk - because it can be use in either of the two (and other disstributions) - so it should import everything from airflow_shared.* and have those packages it imports from as dependencies.

Good find, yes that will likely be needed. Let is be independent as and when possible

Copy link
Contributor

@amoghrajesh amoghrajesh left a comment

Choose a reason for hiding this comment

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

Some observations and comments, looks good otherwise.

import attr

import airflow.serialization.serializers
from airflow._shared.module_loading import import_string, iter_namespace, qualname
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to self: revisit this occurence as part of Move over serde library to task sdk

core_masker.sensitive_variables_fields = list(sensitive_fields)
core_masker.secret_mask_adapter = secret_mask_adapter

# TODO: this should be moved out when settings are moved to `shared`
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont think I follow this one

Raise ImportError if the import failed.
"""
# TODO: Add support for nested classes. Currently, it only works for top-level classes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to? I dont see a use case for it

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope. I just copied it from the original code.

@potiuk potiuk force-pushed the add-prek-hook-for-airflow-imports-in-shared branch from 5b99a82 to 2e8b15b Compare December 6, 2025 17:14
@potiuk
Copy link
Member Author

potiuk commented Dec 6, 2025

Rebased it after observability was added :)

@potiuk potiuk force-pushed the add-prek-hook-for-airflow-imports-in-shared branch from 2e8b15b to ccd119e Compare December 6, 2025 17:28
potiuk added a commit to potiuk/airflow that referenced this pull request Dec 6, 2025
Shared packages should not refer to airflow or airflow.sdk. This
is the last "airflow" import remaining in the observability package.

Fixed during implementation of apache#58825
potiuk added a commit that referenced this pull request Dec 6, 2025
Shared packages should not refer to airflow or airflow.sdk. This
is the last "airflow" import remaining in the observability package.

Fixed during implementation of #58825
amoghrajesh pushed a commit to astronomer/airflow that referenced this pull request Dec 8, 2025
Shared packages should not refer to airflow or airflow.sdk. This
is the last "airflow" import remaining in the observability package.

Fixed during implementation of apache#58825
@potiuk potiuk force-pushed the add-prek-hook-for-airflow-imports-in-shared branch 2 times, most recently from a5b108f to 4752c49 Compare December 8, 2025 21:06
Since we are quite close to having a completed separation between
distributions, this PR will be rebased until we will fix all the
issues - we might want to extract things from this PR as we
rebase it and move the code between distributions.

The following checks were added:

* The shared distributions (neither in src nor tests) should never
  import `from airflow.`

* The distributions that are using shared code "airlfow-core",
  "task-sdk" should never import anything from either
  "airflow_shared" or from "_shared" import coming from another
  distribution.

* Neither "apache-airflow", "apache-airflow-task-sdk", "apache-airflow-core"
  should be added as dependency in a shared distribution.

* The "devel-common" should also not refer to airflow.* - it should only
  import from airflow_shared.*
@potiuk potiuk force-pushed the add-prek-hook-for-airflow-imports-in-shared branch from 4752c49 to b34e1b0 Compare December 20, 2025 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:dev-tools backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants