mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 11:59:35 +00:00
[airflow
] Move AIR301
to AIR002
(#16978)
## Summary Unlike other AIR3XX rules, this best practice can be applied to Airflow 1 and Airflow 2 as well. Thus, we think it might make sense for use to move it to AIR002 so that the first number of the error align to Airflow version as possible to reduce confusion ## Test Plan the test fixture has been updated
This commit is contained in:
parent
5d57788328
commit
33bd08f49b
6 changed files with 17 additions and 15 deletions
|
@ -1068,7 +1068,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
|
|||
|
||||
// airflow
|
||||
(Airflow, "001") => (RuleGroup::Stable, rules::airflow::rules::AirflowVariableNameTaskIdMismatch),
|
||||
(Airflow, "301") => (RuleGroup::Preview, rules::airflow::rules::AirflowDagNoScheduleArgument),
|
||||
(Airflow, "002") => (RuleGroup::Preview, rules::airflow::rules::AirflowDagNoScheduleArgument),
|
||||
(Airflow, "302") => (RuleGroup::Preview, rules::airflow::rules::Airflow3Removal),
|
||||
(Airflow, "303") => (RuleGroup::Preview, rules::airflow::rules::Airflow3MovedToProvider),
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ mod tests {
|
|||
use crate::{assert_messages, settings};
|
||||
|
||||
#[test_case(Rule::AirflowVariableNameTaskIdMismatch, Path::new("AIR001.py"))]
|
||||
#[test_case(Rule::AirflowDagNoScheduleArgument, Path::new("AIR301.py"))]
|
||||
#[test_case(Rule::AirflowDagNoScheduleArgument, Path::new("AIR002.py"))]
|
||||
#[test_case(Rule::Airflow3Removal, Path::new("AIR302_args.py"))]
|
||||
#[test_case(Rule::Airflow3Removal, Path::new("AIR302_names.py"))]
|
||||
#[test_case(Rule::Airflow3Removal, Path::new("AIR302_class_attribute.py"))]
|
||||
|
|
|
@ -9,16 +9,17 @@ use crate::checkers::ast::Checker;
|
|||
|
||||
/// ## What it does
|
||||
/// Checks for a `DAG()` class or `@dag()` decorator without an explicit
|
||||
/// `schedule` parameter.
|
||||
/// `schedule` (or `schedule_interval` for Airflow 1) parameter.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// The default `schedule` value on Airflow 2 is `timedelta(days=1)`, which is
|
||||
/// almost never what a user is looking for. Airflow 3 changes this the default
|
||||
/// to *None*, and would break existing DAGs using the implicit default.
|
||||
/// The default value of the `schedule` parameter on Airflow 2 and
|
||||
/// `schedule_interval` on Airflow 1 is `timedelta(days=1)`, which is almost
|
||||
/// never what a user is looking for. Airflow 3 changed the default value to `None`,
|
||||
/// and would break existing dags using the implicit default.
|
||||
///
|
||||
/// If your DAG does not have an explicit `schedule` argument, Airflow 2
|
||||
/// schedules a run for it every day (at the time determined by `start_date`).
|
||||
/// Such a DAG will no longer be scheduled on Airflow 3 at all, without any
|
||||
/// If your dag does not have an explicit `schedule` / `schedule_interval` argument,
|
||||
/// Airflow 2 schedules a run for it every day (at the time determined by `start_date`).
|
||||
/// Such a dag will no longer be scheduled on Airflow 3 at all, without any
|
||||
/// exceptions or other messages visible to the user.
|
||||
///
|
||||
/// ## Example
|
||||
|
@ -49,7 +50,7 @@ impl Violation for AirflowDagNoScheduleArgument {
|
|||
}
|
||||
}
|
||||
|
||||
/// AIR301
|
||||
/// AIR002
|
||||
pub(crate) fn dag_no_schedule_argument(checker: &Checker, expr: &Expr) {
|
||||
if !checker.semantic().seen_module(Modules::AIRFLOW) {
|
||||
return;
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/airflow/mod.rs
|
||||
snapshot_kind: text
|
||||
---
|
||||
AIR301.py:4:1: AIR301 DAG should have an explicit `schedule` argument
|
||||
AIR002.py:4:1: AIR002 DAG should have an explicit `schedule` argument
|
||||
|
|
||||
2 | from airflow.timetables.simple import NullTimetable
|
||||
3 |
|
||||
4 | DAG(dag_id="class_default_schedule")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AIR301
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AIR002
|
||||
5 |
|
||||
6 | DAG(dag_id="class_schedule", schedule="@hourly")
|
||||
|
|
||||
|
||||
AIR301.py:13:2: AIR301 DAG should have an explicit `schedule` argument
|
||||
AIR002.py:13:2: AIR002 DAG should have an explicit `schedule` argument
|
||||
|
|
||||
13 | @dag()
|
||||
| ^^^^^ AIR301
|
||||
| ^^^^^ AIR002
|
||||
14 | def decorator_default_schedule():
|
||||
15 | pass
|
||||
|
|
2
ruff.schema.json
generated
2
ruff.schema.json
generated
|
@ -2943,9 +2943,9 @@
|
|||
"AIR0",
|
||||
"AIR00",
|
||||
"AIR001",
|
||||
"AIR002",
|
||||
"AIR3",
|
||||
"AIR30",
|
||||
"AIR301",
|
||||
"AIR302",
|
||||
"AIR303",
|
||||
"ALL",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue