Skip to content

[airflow] add autofix to AIR302 ProviderName #17038

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

Closed
wants to merge 1 commit into from

Conversation

Lee-W
Copy link
Contributor

@Lee-W Lee-W commented Mar 28, 2025

Summary

Add autofix to AIR303 name moved to provider

Test Plan

The existing test fixture reflects the update

@Lee-W
Copy link
Contributor Author

Lee-W commented Mar 28, 2025

this branch based on #16965

Copy link
Contributor

github-actions bot commented Mar 28, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dhruvmanila
Copy link
Member

(I'll avoid reviewing this PR for now as it's in draft and it's based on a different branch; the diff includes code from both branches. Once the dependent PR is merged, we can move this out of draft and I can review it.)

@dhruvmanila dhruvmanila added fixes Related to suggested fixes for violations preview Related to preview mode features labels Mar 31, 2025
@Lee-W Lee-W force-pushed the autofix-AIR303 branch 2 times, most recently from 410c3e9 to bc93544 Compare April 2, 2025 15:37
@Lee-W Lee-W marked this pull request as ready for review April 2, 2025 15:37
@Lee-W
Copy link
Contributor Author

Lee-W commented Apr 2, 2025

@dhruvmanila This PR is ready now 🙌 (after all the merging and rebasing 💦)

@Lee-W Lee-W marked this pull request as draft April 2, 2025 16:07
@dhruvmanila
Copy link
Member

@dhruvmanila This PR is ready now 🙌 (after all the merging and rebasing 💦)

You've put this back into draft, is that intentional?

@Lee-W
Copy link
Contributor Author

Lee-W commented Apr 3, 2025

Yep, it is. Found an issue after a few more rebasing. Was trying to fix it but couldn't do it on time. 🥲

@Lee-W Lee-W changed the title [airflow] add autofix to AIR303 ProviderName [airflow] add autofix to AIR302 ProviderName Apr 7, 2025
},
["airflow", "sensors", "s3_key_sensor", "S3KeySensor"] => Replacement::ProviderName{
["airflow", "operators", "google_api_to_s3_transfer", "GoogleApiToS3Operator"] => {
Replacement::ProviderName {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @ntBre, a quick question. I tried to apply autofix to all the similar symbol changes, but only a few of them can be fixed. Do you know what might be missing?

Copy link
Contributor

Choose a reason for hiding this comment

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

I might be missing some context here. What kind of autofix were you trying to apply? Or what change were you trying to make?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ntBre

for example, if the user is using

from airflow.operators.google_api_to_s3_transfer import GoogleApiToS3Operator

GoogleApiToS3Operator()

we want to fix it as

from airflow.providers.amazon.aws.transfers.google_api_to_s3 import GoogleApiToS3Operator

GoogleApiToS3Operator()

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried adding an unwrap call instead of ? on the get_or_import_symbol call, and I'm seeing this error when running the AIR302 tests:

called `Result::unwrap()` on an `Err` value: ConflictingName("provide_bucket_name")

It looks like you can't overwrite an existing symbol with a different import path, at least through the get_or_import_symbol API.

I don't really have a great suggestion for working around this. You could try a direct text replacement, but I can easily imagine that going wrong if there are multiple imports grouped together or something like that.

Maybe a better alternative would be a custom version of Importer::import_symbol (inside of a custom get_or_import_symbol) that ignores the ConflictingName error case since you're overwriting it anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Ah yes, I think that updating an existing import isn't currently supported and you'd need to add a dedicated edit infrastructure for it. The NumPy deprecation rules doesn't support that either so it should be fine for now unless you'd want to add support for it.

Copy link
Member

Choose a reason for hiding this comment

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

Although this doesn't look too difficult and we could potentially use a text replacement as suggested by Brent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's crucial for us. I'll explore a bit and see how I can achieve it. Before that, I'll apply AutoImport to fixable ones.

@ntBre ntBre self-assigned this Apr 9, 2025
@Lee-W Lee-W closed this Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixes Related to suggested fixes for violations preview Related to preview mode features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants