Add pre-commit hook to prevent test-only imports in production source#61713
Merged
shahar1 merged 1 commit intoapache:mainfrom Feb 10, 2026
Merged
Conversation
jason810496
reviewed
Feb 10, 2026
68ae9df to
d6b639c
Compare
Contributor
Author
Yeah, just figured that I've missed it :) |
60286cc to
3fec785
Compare
081aeca to
aa5a9d8
Compare
1 task
This was referenced Feb 10, 2026
aa5a9d8 to
816730d
Compare
816730d to
4580241
Compare
shahar1
commented
Feb 10, 2026
jason810496
approved these changes
Feb 10, 2026
Backport failed to create: v3-1-test. View the failure log Run details
You can attempt to backport this manually by running: cherry_picker 6983599 v3-1-testThis should apply the commit to the v3-1-test branch and leave the commit in conflict state marking After you have resolved the conflicts, you can continue the backport process by running: cherry_picker --continueIf you don't have cherry-picker installed, see the installation guide. |
Contributor
|
Cool! |
Alok-kumar-priyadarshi
pushed a commit
to Alok-kumar-priyadarshi/airflow
that referenced
this pull request
Feb 11, 2026
Ratasa143
pushed a commit
to Ratasa143/airflow
that referenced
this pull request
Feb 15, 2026
choo121600
pushed a commit
to choo121600/airflow
that referenced
this pull request
Feb 22, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
related: #60662
Adds a pre-commit hook that prevents test-only module imports from leaking into production source code (
*/src/). This addresses the class of bugs demonstrated by #61673, where atests_commonimport in the kubernetes provider caused aModuleNotFoundErrorat runtime.The hook detects two categories of forbidden imports:
tests_common.*— theapache-airflow-devel-commonpackage is dev-only.*.tests.*/tests.*— any import whose module path contains a.tests.component (e.g.from providers.cncf.kubernetes.tests.foo import bar). Test directories are not shipped in package wheels.Note (S.E.): the latter should be a relatively low risk because of how the current namespaces work. It could be somewhat helpful in case you messed up the imports while working locally, but such cases could be indicated quickly. I could remove if it's an overkill, the
tests_commonuse case is more prone.Strictness (see comment on the PR regarding necessity):
All imports from these modules are forbidden, including those guarded by
if TYPE_CHECKING:.This PR also fixes an existing violation in
BashOperator(standard provider) by movingArgNotSetcompatibility logic toversion_compat.py.The hook is AST-based (similar to
check_airflow_imports_in_shared.py) and runs on allsrc/files.Was generative AI tooling used to co-author this PR?
Generated-by: GitHub Copilot following the guidelines