[airflow] Extract common utilities for use in new rules#23630
[airflow] Extract common utilities for use in new rules#23630Dev-iL wants to merge 1 commit intoastral-sh:mainfrom
airflow] Extract common utilities for use in new rules#23630Conversation
Move these decorator-checking functions from removal_in_3.rs (AIR301) to helpers.rs so they can be reused by other airflow rules. The shared versions now also match the airflow.sdk.task import path and handle @task.<variant> forms (e.g., @task.branch, @task.short_circuit), ensuring AIR301 context checks work for both Airflow 2 and 3 decorator imports. Co-Authored-By: Claude Opus 4.6 <[email protected]>
a786ed8 to
29ab30f
Compare
|
|
Is this an expansion of what |
Yes, the rule is changed by this, but this is more of a byproduct of the refactor. In theory, AIR301 becomes more comprehensive in catching deprecated patterns across different Airflow versions. In practice however, I would expect to see new hits in the ecosystem scan of the airflow codebase - which is not the case. |
| // Match `@task.<variant>` (e.g., `@task.branch`, `@task.short_circuit`). | ||
| if let Expr::Attribute(ExprAttribute { value, .. }) = expr { | ||
| return semantic.resolve_qualified_name(value).is_some_and(|qn| { | ||
| matches!(qn.segments(), ["airflow", "decorators" | "sdk", "task"]) | ||
| }); | ||
| } |
There was a problem hiding this comment.
Can you add a test case exercising this?
| /// Returns `true` if the current statement hierarchy has a function that's decorated with | ||
| /// `@airflow.decorators.task` or `@airflow.sdk.task`. | ||
| pub(crate) fn in_airflow_task_function(semantic: &SemanticModel) -> bool { | ||
| semantic | ||
| .current_statements() | ||
| .find_map(|stmt| stmt.as_function_def_stmt()) | ||
| .is_some_and(|function_def| is_airflow_task(function_def, semantic)) | ||
| } |
There was a problem hiding this comment.
Prefer to have this above is_airflow_task since it depends on it.
Summary
Extract
is_airflow_taskandin_airflow_task_functionfromremoval_in_3.rs(AIR301) into the sharedhelpers.rsmodule so they can be reused by other airflow rules.The shared versions include two enhancements over the original private implementations:
airflow.decorators.taskandairflow.sdk.taskimport paths, supporting Airflow 2 and 3 decorator imports.@task.<variant>decorator forms (e.g.,@task.branch,@task.short_circuit), not just@taskand@task().Test Plan
Added
airflow.sdktest cases toAIR301_context.pyconfirming that deprecated context key detection works under both@task(fromairflow.decorators) and@sdk_task(fromairflow.sdk). Existing AIR301 tests continue to pass.RUFF_UPDATE_SCHEMA=1 cargo nextest run -p ruff_linter -- "airflow::tests" cargo clippy -p ruff_linter --all-targets --all-features -- -D warningsRelated: #23579 #23584