Skip to content

Conversation

@amoghrajesh
Copy link
Contributor

This PR adds a provider-version-compat pre-commit hook that ensures each provider only imports from its own version_compat module.

This is to avoid situations like: #52819 (comment)

This will also be of use in longer run to avoid cross provider imports and to avoid any unexpected possibilities.

Working:
In base_aws.py, changed the version_compat import to:

from airflow.providers.facebook.version_compat import BaseOperator

pre-commit run provider-version-compat --files providers/amazon/src/airflow/providers/amazon/aws/operators/base_aws.py

Result:

(airflow) ➜  airflow git:(precommit-for-version-compat) ✗ pre-commit run provider-version-compat --files providers/amazon/src/airflow/providers/amazon/aws/operators/base_aws.py
Check for correct version_compat imports in providers.......................Failed
- hook id: provider-version-compat
- exit code: 1
- files were modified by this hook

[pre-commit] providers/amazon/src/airflow/providers/amazon/aws/operators/base_aws.py: Import from wrong provider: facebook (should be amazon)
[pre-commit] Fixed some imports. Please re-add and commit.


^ 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 Jul 5, 2025
@amoghrajesh amoghrajesh changed the title Precommit for version compat Add pre-commit hook to check provider uses its own version_compat import Jul 5, 2025
Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

NICE .. Indeed that can happen very easily!

@potiuk potiuk merged commit d11ceb6 into apache:main Jul 5, 2025
104 checks passed
@potiuk potiuk removed the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label Jul 5, 2025
@potiuk
Copy link
Member

potiuk commented Jul 5, 2025

no need to backport

@github-actions
Copy link

github-actions bot commented Jul 5, 2025

Backport failed to create: v3-0-test. View the failure log Run details

Status Branch Result
v3-0-test Commit Link

You can attempt to backport this manually by running:

cherry_picker d11ceb6 v3-0-test

This should apply the commit to the v3-0-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:

cherry_picker --continue

HsiuChuanHsu pushed a commit to HsiuChuanHsu/airflow that referenced this pull request Jul 10, 2025
…ort (apache#52898)

* Add pre-commit hook to check provider uses its own version_compat import

* move to scripts/ci

* correct executable perms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants