Skip to content

[airflow] Add autofix infrastructure to AIR302 name checks #16965

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

Merged
merged 6 commits into from
Apr 2, 2025

Conversation

Lee-W
Copy link
Contributor

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

Summary

Add autofix logic to "airflow", "api_connexion", "security", "requires_access_dataset", "airflow", "Dataset" and "airflow", "datasets", "Dataset"

Test Plan

The existing test fixture reflects the update

@Lee-W
Copy link
Contributor Author

Lee-W commented Mar 25, 2025

This is intentionally to be kept simple for easier review. I can update the rest nams in this or the following PR after we agree on how this should work. Thanks!

Copy link
Contributor

github-actions bot commented Mar 25, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+4 -78 violations, +0 -0 fixes in 5 projects; 50 projects unchanged)

apache/airflow (+0 -59 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

- airflow-core/src/airflow/cli/commands/dag_command.py:269:14: S603 `subprocess` call: check for execution of untrusted input
- airflow-core/tests/unit/utils/test_process_utils.py:146:30: S603 `subprocess` call: check for execution of untrusted input
- airflow-core/tests/unit/utils/test_process_utils.py:152:23: S603 `subprocess` call: check for execution of untrusted input
- airflow-core/tests/unit/utils/test_process_utils.py:157:23: S603 `subprocess` call: check for execution of untrusted input
- airflow-core/tests/unit/utils/test_process_utils.py:165:25: S603 `subprocess` call: check for execution of untrusted input
- airflow-core/tests/unit/utils/test_process_utils.py:173:25: S603 `subprocess` call: check for execution of untrusted input
- dev/breeze/src/airflow_breeze/commands/main_command.py:138:26: S603 `subprocess` call: check for execution of untrusted input
- dev/breeze/src/airflow_breeze/commands/main_command.py:184:27: S603 `subprocess` call: check for execution of untrusted input
- dev/breeze/src/airflow_breeze/commands/setup_commands.py:151:13: S603 `subprocess` call: check for execution of untrusted input
- dev/breeze/src/airflow_breeze/commands/setup_commands.py:153:17: S603 `subprocess` call: check for execution of untrusted input
- dev/breeze/src/airflow_breeze/utils/reinstall.py:43:21: S603 `subprocess` call: check for execution of untrusted input
- dev/breeze/src/airflow_breeze/utils/reinstall.py:50:23: S603 `subprocess` call: check for execution of untrusted input
- kubernetes-tests/tests/kubernetes_tests/test_base.py:124:19: S603 `subprocess` call: check for execution of untrusted input
- kubernetes-tests/tests/kubernetes_tests/test_base.py:239:21: S603 `subprocess` call: check for execution of untrusted input
- providers/google/tests/unit/google/cloud/log/test_gcs_task_handler_system.py:78:20: S603 `subprocess` call: check for execution of untrusted input
- providers/google/tests/unit/google/cloud/log/test_gcs_task_handler_system.py:79:20: S603 `subprocess` call: check for execution of untrusted input
- providers/google/tests/unit/google/cloud/log/test_stackdriver_task_handler_system.py:67:20: S603 `subprocess` call: check for execution of untrusted input
- providers/google/tests/unit/google/cloud/log/test_stackdriver_task_handler_system.py:68:20: S603 `subprocess` call: check for execution of untrusted input
- providers/google/tests/unit/google/cloud/log/test_stackdriver_task_handler_system.py:83:20: S603 `subprocess` call: check for execution of untrusted input
- providers/google/tests/unit/google/cloud/log/test_stackdriver_task_handler_system.py:84:20: S603 `subprocess` call: check for execution of untrusted input
- scripts/ci/pre_commit/breeze_cmd_line.py:63:14: S603 `subprocess` call: check for execution of untrusted input
- scripts/ci/pre_commit/breeze_cmd_line.py:79:11: S603 `subprocess` call: check for execution of untrusted input
- scripts/ci/pre_commit/breeze_cmd_line.py:88:7: S603 `subprocess` call: check for execution of untrusted input
- scripts/ci/pre_commit/check_kubeconform.py:30:13: S603 `subprocess` call: check for execution of untrusted input
- scripts/ci/pre_commit/check_kubeconform.py:43:10: S603 `subprocess` call: check for execution of untrusted input
- scripts/ci/pre_commit/check_min_python_version.py:34:9: S603 `subprocess` call: check for execution of untrusted input
- scripts/ci/pre_commit/compile_fab_assets.py:76:18: S603 `subprocess` call: check for execution of untrusted input
- scripts/ci/pre_commit/compile_fab_assets.py:88:5: S603 `subprocess` call: check for execution of untrusted input
- scripts/ci/pre_commit/compile_lint_ui.py:35:5: S603 `subprocess` call: check for execution of untrusted input
- scripts/ci/pre_commit/compile_lint_ui.py:36:5: S603 `subprocess` call: check for execution of untrusted input
- scripts/ci/pre_commit/compile_lint_ui.py:39:5: S603 `subprocess` call: check for execution of untrusted input
- scripts/ci/pre_commit/compile_lint_ui.py:40:5: S603 `subprocess` call: check for execution of untrusted input
- scripts/ci/pre_commit/compile_lint_ui.py:41:5: S603 `subprocess` call: check for execution of untrusted input
- scripts/ci/pre_commit/compile_lint_ui.py:44:5: S603 `subprocess` call: check for execution of untrusted input
- scripts/ci/pre_commit/compile_lint_ui.py:46:5: S603 `subprocess` call: check for execution of untrusted input
... 24 additional changes omitted for project

apache/superset (+3 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

+ scripts/change_detector.py:103:5: DOC501 Raised exception `ValueError` missing from docstring
- scripts/change_detector.py:103:5: DOC501 Raised exception `ValueError` missing from docstring
+ scripts/change_detector.py:142:65: RUF100 [*] Unused `noqa` directive (unused: `S603`)
+ setup.py:33:73: RUF100 [*] Unused `noqa` directive (unused: `S603`)

bokeh/bokeh (+0 -8 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

- examples/output/apis/server_document/flask_server.py:45:17: S603 `subprocess` call: check for execution of untrusted input
- scripts/hooks/protect_branches.py:10:22: S603 `subprocess` call: check for execution of untrusted input
- setup.py:52:16: S603 `subprocess` call: check for execution of untrusted input
- tests/codebase/test_code_quality.py:118:13: S603 `subprocess` call: check for execution of untrusted input
- tests/codebase/test_eslint.py:37:12: S603 `subprocess` call: check for execution of untrusted input
- tests/codebase/test_no_request_host.py:50:13: S603 `subprocess` call: check for execution of untrusted input
- tests/codebase/test_ruff.py:33:12: S603 `subprocess` call: check for execution of untrusted input
- tests/test_bokehjs.py:34:16: S603 `subprocess` call: check for execution of untrusted input

rotki/rotki (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

+ rotkehlchen/tests/unit/test_search.py:60:40: RUF100 [*] Unused `noqa` directive (unused: `S603`)

zulip/zulip (+0 -10 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

- scripts/lib/check_rabbitmq_queue.py:146:26: S603 `subprocess` call: check for execution of untrusted input
- scripts/lib/puppet_cache.py:25:30: S603 `subprocess` call: check for execution of untrusted input
- tools/lib/provision.py:271:16: S603 `subprocess` call: check for execution of untrusted input
- tools/lib/provision_inner.py:109:14: S603 `subprocess` call: check for execution of untrusted input
- tools/lib/test_script.py:125:5: S603 `subprocess` call: check for execution of untrusted input
- zerver/data_import/mattermost.py:443:19: S603 `subprocess` call: check for execution of untrusted input
- zerver/lib/test_fixtures.py:344:5: S603 `subprocess` call: check for execution of untrusted input
- zerver/logging_handlers.py:8:16: S603 `subprocess` call: check for execution of untrusted input
- zerver/management/commands/compilemessages.py:76:18: S603 `subprocess` call: check for execution of untrusted input
- zerver/management/commands/makemessages.py:207:21: S603 `subprocess` call: check for execution of untrusted input

Changes by rule (3 rules affected)

code total + violation - violation + fix - fix
S603 77 0 77 0 0
RUF100 3 3 0 0 0
DOC501 2 1 1 0 0

@ntBre ntBre added the fixes Related to suggested fixes for violations label Mar 26, 2025
@Lee-W Lee-W force-pushed the autofix-AIR302 branch 3 times, most recently from 17ddcf4 to e4d614d Compare March 28, 2025 09:09
@Lee-W Lee-W force-pushed the autofix-AIR302 branch 3 times, most recently from d12e9e3 to 773b73a Compare March 31, 2025 10:48
@kaxil
Copy link
Contributor

kaxil commented Mar 31, 2025

Gentle reminder @dhruvmanila

@Lee-W Lee-W mentioned this pull request Mar 31, 2025
2 tasks
Copy link
Member

Choose a reason for hiding this comment

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

We usually don't include any logic in mod.rs for a plugin. Any common logic to multiple rules in a plugin would go under airflow/helpers.rs file.

But, I see that the logic in this file is same as the one from numpy_2_0_deprecation.rs. I'd suggest to reuse the same infrastructure to avoid code duplication. What you can do is move the necessary code from numpy/rules/numpy_2_0_deprecation.rs to numpy/helpers.rs, make the necessary APIs pub(crate) and reuse them in airflow/rules/removal_in_3.rs.

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'm trying to extract some of the common code to numpy/helpers.rs and airflow/helper.rs. But the structure is a bit different. Not sure whether we can reuse the whole is_guarded_by_try_except logic here

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see. It's fine to not reuse is_guarded_by_try_accept then and have a logic specific to Airflow.

@dhruvmanila dhruvmanila added the preview Related to preview mode features label Mar 31, 2025
@@ -0,0 +1,64 @@
use crate::rules::numpy::helpers::ImportSearcher;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is moved here so that we can reused it after we reorg airflow rules

Airflow3Removal {
deprecated: qualified_name.to_string(),
replacement,
replacement: replacement.clone(),
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 tried to move the fix a bit but did not succeeded. Should we refactor the fix here as well?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I follow here. Do you mean to avoid the clone here that I suggested in your other PRs?

Copy link
Member

Choose a reason for hiding this comment

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

If it requires too much effort then it's fine to avoid making the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean to avoid the clone here that I suggested in your other PRs?

Yep

If it requires too much effort then it's fine to avoid making the change.

We can probably do that in a following PR

@Lee-W Lee-W force-pushed the autofix-AIR302 branch 3 times, most recently from 3493e97 to 28aa74d Compare April 1, 2025 09:52
Lee-W added a commit to astronomer/airflow that referenced this pull request Apr 1, 2025
Lee-W added a commit to astronomer/airflow that referenced this pull request Apr 1, 2025
Lee-W added a commit to astronomer/airflow that referenced this pull request Apr 1, 2025
Lee-W added a commit to astronomer/airflow that referenced this pull request Apr 2, 2025
Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

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

Looks good. Are you going to now change other Replacement::Name to use Replacement::AutoImport?

semantic: &SemanticModel,
) -> bool {
match expr {
Expr::Name(ExprName { id, .. }) => {
Copy link
Member

Choose a reason for hiding this comment

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

Is this always going to be a Name node? Can it be an Attribute node?

For example, in NumPy deprecation rules, there's this test case:

try:
exc = np.exceptions.ComplexWarning
except AttributeError:
exc = np.ComplexWarning # `except AttributeError` means that this is okay

Is something like that possible? It's totally fine if you don't want to support something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll want to add it. But I'm thinking of addressing it in another PR. @sunank200 will take over during the time I'm out.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. Should I go merge this PR then?

Enjoy your time off!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, it would be super helpful if we could merge it first (also unblock a few draft PR). Let me resolve the conflict now!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated 🙌

@Lee-W
Copy link
Contributor Author

Lee-W commented Apr 2, 2025

Looks good. Are you going to now change other Replacement::Name to use Replacement::AutoImport?

I'm thinking of making it another PR. @sunank200 will take over during the time I'm out.

@dhruvmanila dhruvmanila changed the title [airflow] add autofix to AIR302 check_name [airflow] Add autofix infrastructure to AIR302 name checks Apr 2, 2025
@dhruvmanila dhruvmanila enabled auto-merge (squash) April 2, 2025 15:27
@dhruvmanila dhruvmanila merged commit f989c2c into astral-sh:main Apr 2, 2025
21 checks passed
dcreager added a commit that referenced this pull request Apr 3, 2025
* origin/main: (35 commits)
  [red-knot] Callable types are disjoint from literals (#17160)
  [red-knot] Fix inference for `pow` between two literal integers (#17161)
  [red-knot] Add GitHub PR annotations when mdtests fail in CI (#17150)
  [red-knot] Fix equivalence of differently ordered unions that contain `Callable` types (#17145)
  [red-knot] Add initial set of tests for unreachable code (#17159)
  [`airflow`] Move `AIR302` to `AIR301` and `AIR303` to `AIR302` (#17151)
  ruff_db: simplify lifetimes on `DiagnosticDisplay`
  [red-knot] Detect division-by-zero in unions and intersections (#17157)
  [`airflow`] Add autofix infrastructure to `AIR302` name checks (#16965)
  [`flake8-bandit`] Mark `str` and `list[str]` literals as trusted input (`S603`) (#17136)
  [`airflow`] Add autofix for `AIR302` attribute checks (#16977)
  [`airflow`] Extend `AIR302` with additional symbols (#17085)
  [`airflow`] Move `AIR301` to `AIR002` (#16978)
  [`airflow`] Add autofix for `AIR302` method checks (#16976)
  ruff_db: switch diagnostic rendering over to `std::fmt::Display`
  [red-knot] Add 'Goto type definition' to the playground (#17055)
  red_knot_ide: update snapshots
  red_knot_python_semantic: remove comment about `TypeCheckDiagnostic`
  ruff_db: delete most of the old diagnostic code
  red_knot: use `Diagnostic` inside of red knot
  ...
dcreager added a commit that referenced this pull request Apr 3, 2025
* origin/main: (82 commits)
  [red-knot] Fix more [redundant-cast] false positives (#17170)
  [red-knot] Three-argument type-calls take 'str' as the first argument (#17168)
  Control flow: `return` and `raise` (#17121)
  Bump 0.11.3 (#17173)
  [red-knot] Improve `Debug` implementation for `semantic_index::SymbolTable` (#17172)
  [red-knot] Fix `str(…)` calls (#17163)
  [red-knot] visibility_constraint analysis for match cases (#17077)
  [red-knot] Fix playground crashes when diagnostics are stale (#17165)
  [red-knot] Callable types are disjoint from literals (#17160)
  [red-knot] Fix inference for `pow` between two literal integers (#17161)
  [red-knot] Add GitHub PR annotations when mdtests fail in CI (#17150)
  [red-knot] Fix equivalence of differently ordered unions that contain `Callable` types (#17145)
  [red-knot] Add initial set of tests for unreachable code (#17159)
  [`airflow`] Move `AIR302` to `AIR301` and `AIR303` to `AIR302` (#17151)
  ruff_db: simplify lifetimes on `DiagnosticDisplay`
  [red-knot] Detect division-by-zero in unions and intersections (#17157)
  [`airflow`] Add autofix infrastructure to `AIR302` name checks (#16965)
  [`flake8-bandit`] Mark `str` and `list[str]` literals as trusted input (`S603`) (#17136)
  [`airflow`] Add autofix for `AIR302` attribute checks (#16977)
  [`airflow`] Extend `AIR302` with additional symbols (#17085)
  ...
maxmynter pushed a commit to maxmynter/ruff that referenced this pull request Apr 3, 2025
…l-sh#16965)

## Summary

Add autofix infrastructure to `AIR302` name checks and use this logic to 
fix`"airflow", "api_connexion", "security", "requires_access_dataset"`, `"airflow", "Dataset"` and `"airflow",
"datasets", "Dataset"`

## Test Plan

The existing test fixture reflects the update
Lee-W added a commit to astronomer/airflow that referenced this pull request Apr 4, 2025
Lee-W added a commit to apache/airflow that referenced this pull request Apr 7, 2025
simonprydden pushed a commit to simonprydden/airflow that referenced this pull request Apr 8, 2025
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request May 29, 2025
…#16965 (#48618)

GitOrigin-RevId: 59d765e0a9f5dcc6d4c0c5b93f7b7a55e67a1868
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.

4 participants