You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "shahar1 (via GitHub)" <gi...@apache.org> on 2026/02/10 08:47:47 UTC
[PR] Add pre-commit hook to prevent runtime tests_common imports [airflow]
shahar1 opened a new pull request, #61713:
URL: https://github.com/apache/airflow/pull/61713
Use AST analysis to ensure `tests_common` (a dev-only package) is not imported in production source files (`airflow-core`, `providers`, etc.) except under `TYPE_CHECKING` guards.
This prevents runtime `ModuleNotFoundError` regressions like #61673, where test utilities are available in CI but missing in production images and PyPI installs.
**Details:**
- Adds `scripts/ci/prek/check_tests_common_imports_in_src.py`
- Registers the hook in `.pre-commit-config.yaml` for:
- `airflow-core/src/`
- `airflow-ctl/src/`
- `providers/*/src/`
- `task-sdk/src/`
- `shared/*/src/`
This hook will fail if any production file imports `tests_common` at runtime.
---
##### Was generative AI tooling used to co-author this PR?
- [x] Yes (please specify the tool below)
Generated-by: GitHub Copilot following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
---
* Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
* For fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
* When adding dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
* For significant user-facing changes create newsfragment: `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add pre-commit hook to prevent test-only imports in production source [airflow]
Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 commented on PR #61713:
URL: https://github.com/apache/airflow/pull/61713#issuecomment-3876350473
> It seems we haven't added corresponding entry in `.pre-commit-config.yaml`.
Yeah, just figured that I've missed it :)
Also, I'm expanding it to imports from `tests` in general (not only `test_common`).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add pre-commit hook to prevent test-only imports in production source [airflow]
Posted by "jscheffl (via GitHub)" <gi...@apache.org>.
jscheffl commented on PR #61713:
URL: https://github.com/apache/airflow/pull/61713#issuecomment-3880475806
Cool!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add pre-commit hook to prevent test-only imports in production source [airflow]
Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 merged PR #61713:
URL: https://github.com/apache/airflow/pull/61713
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add pre-commit hook to prevent test-only imports in production source [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #61713:
URL: https://github.com/apache/airflow/pull/61713#issuecomment-3879591036
### Backport failed to create: v3-1-test. View the failure log <a href='https://github.com/apache/airflow/actions/runs/21875221266'> Run details </a>
<table>
<tr>
<th>Status</th>
<th>Branch</th>
<th>Result</th>
</tr>
<tr>
<td>❌</td>
<td>v3-1-test</td>
<td><a href="https://github.com/apache/airflow/commit/69835999e996b9bf92fb947117fb86e1a723933d"><img src='https://img.shields.io/badge/Commit-6983599-red' alt='Commit Link'></a></td>
</tr>
</table>
You can attempt to backport this manually by running:
```bash
cherry_picker 6983599 v3-1-test
```
This should apply the commit to the v3-1-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.
After you have resolved the conflicts, you can continue the backport process by running:
```bash
cherry_picker --continue
```
If you don't have cherry-picker installed, see the [installation guide](https://github.com/apache/airflow/blob/main/dev/README_AIRFLOW3_DEV.md#how-to-backport-pr-with-cherry-picker-cli).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add pre-commit hook to prevent test-only imports in production source [airflow]
Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 commented on code in PR #61713:
URL: https://github.com/apache/airflow/pull/61713#discussion_r2787522475
##########
providers/standard/src/airflow/providers/standard/operators/bash.py:
##########
@@ -34,8 +34,7 @@
if TYPE_CHECKING:
from airflow.providers.common.compat.sdk import Context
-
- from tests_common.test_utils.version_compat import ArgNotSet
Review Comment:
We could exclude import statements under `TYPE_CHECKING`, as production code shouldn't get there anyway. However, it could be prone to future misuse - thoughts?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add pre-commit hook to prevent test-only imports in production source [airflow]
Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 commented on code in PR #61713:
URL: https://github.com/apache/airflow/pull/61713#discussion_r2787522475
##########
providers/standard/src/airflow/providers/standard/operators/bash.py:
##########
@@ -34,8 +34,7 @@
if TYPE_CHECKING:
from airflow.providers.common.compat.sdk import Context
-
- from tests_common.test_utils.version_compat import ArgNotSet
Review Comment:
We could exclude it, as production code shouldn't get there anyway - but it could be prone to future misuse. Thoughts?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add pre-commit hook to prevent test-only imports in production source [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #61713:
URL: https://github.com/apache/airflow/pull/61713#discussion_r2789206310
##########
providers/standard/src/airflow/providers/standard/operators/bash.py:
##########
@@ -34,8 +34,7 @@
if TYPE_CHECKING:
from airflow.providers.common.compat.sdk import Context
-
- from tests_common.test_utils.version_compat import ArgNotSet
Review Comment:
> it could be potentially prone to future misuse
Yes, I agree with that. I will vote for not using test modules even under `TYPE_CHECKING` to avoid future misuse. Additionally, if we really need those type annotation, it would be better to place under version compat module or just having small part of duplication.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add pre-commit hook to prevent test-only imports in production source [airflow]
Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 commented on code in PR #61713:
URL: https://github.com/apache/airflow/pull/61713#discussion_r2787522475
##########
providers/standard/src/airflow/providers/standard/operators/bash.py:
##########
@@ -34,8 +34,7 @@
if TYPE_CHECKING:
from airflow.providers.common.compat.sdk import Context
-
- from tests_common.test_utils.version_compat import ArgNotSet
Review Comment:
We could exclude import statements under `TYPE_CHECKING`, as production code shouldn't get there anyway. However, it could be potentially prone to future misuse - thoughts?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org