Skip to content

Commit

Permalink
Remove check for deprecated arguments from AIR301
Browse files Browse the repository at this point in the history
We'll do them in AIR302 instead.
  • Loading branch information
uranusjr committed Nov 26, 2024
1 parent 08520d6 commit 83feee3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 105 deletions.
15 changes: 0 additions & 15 deletions crates/ruff_linter/resources/test/fixtures/airflow/AIR301.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
from airflow import DAG, dag
from airflow.timetables.trigger import CronTriggerTimetable

DAG(dag_id="class_default_schedule")

DAG(dag_id="class_schedule", schedule="@hourly")

DAG(dag_id="class_timetable", timetable=CronTriggerTimetable())

DAG(dag_id="class_schedule_interval", schedule_interval="@hourly")


@dag()
def decorator_default_schedule():
Expand All @@ -18,13 +13,3 @@ def decorator_default_schedule():
@dag(schedule="0 * * * *")
def decorator_schedule():
pass


@dag(timetable=CronTriggerTimetable())
def decorator_timetable():
pass


@dag(schedule_interval="0 * * * *")
def decorator_schedule_interval():
pass
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::Expr;
use ruff_python_ast::{self as ast, Keyword};
use ruff_python_ast::{self as ast};
use ruff_text_size::Ranged;

use crate::checkers::ast::Checker;
Expand All @@ -20,20 +20,13 @@ use crate::checkers::ast::Checker;
/// Such a DAG will no longer be scheduled on Airflow 3 at all, without any
/// exceptions or other messages visible to the user.
///
/// Airflow 2 also provides alternative arguments `schedule_interval` and
/// `timetable` to specify the DAG schedule. They existed for backward
/// compatibility, and have been removed from Airflow 3.
///
/// ## Example
/// ```python
/// from airflow import DAG
///
///
/// # Using the implicit default schedule.
/// dag1 = DAG(dag_id="my_dag_1")
///
/// # Using a deprecated argument to set schedule.
/// dag2 = DAG(dag_id="my_dag_2", schedule_interval="@daily")
/// dag = DAG(dag_id="my_dag")
/// ```
///
/// Use instead:
Expand All @@ -43,26 +36,15 @@ use crate::checkers::ast::Checker;
/// from airflow import DAG
///
///
/// dag1 = DAG(dag_id="my_dag_1", schedule=timedelta(days=1))
/// dag2 = DAG(dag_id="my_dag_2", schedule="@daily")
/// dag = DAG(dag_id="my_dag", schedule=timedelta(days=1))
/// ```
#[violation]
pub struct AirflowDagNoScheduleArgument {
deprecated_argument: Option<String>,
}
pub struct AirflowDagNoScheduleArgument;

impl Violation for AirflowDagNoScheduleArgument {
#[derive_message_formats]
fn message(&self) -> String {
let AirflowDagNoScheduleArgument {
deprecated_argument,
} = self;
match deprecated_argument {
Some(argument) => {
format!("argument `{argument}` is deprecated; use `schedule` instead")
}
None => "DAG should have an explicit `schedule` argument".to_string(),
}
"DAG should have an explicit `schedule` argument".to_string()
}
}

Expand Down Expand Up @@ -91,28 +73,7 @@ pub(crate) fn dag_no_schedule_argument(checker: &mut Checker, expr: &Expr) {
return;
}

// Produce a diagnostic on either a deprecated schedule keyword argument,
// or no schedule-related keyword arguments at all.
let diagnostic = if let Some(keyword) = arguments.keywords.iter().find(|keyword| {
let Keyword { arg, .. } = keyword;
arg.as_ref()
.is_some_and(|arg| matches!(arg.as_str(), "timetable" | "schedule_interval"))
}) {
// A deprecated argument is used.
Diagnostic::new(
AirflowDagNoScheduleArgument {
deprecated_argument: keyword.arg.as_ref().map(ToString::to_string),
},
keyword.range(),
)
} else {
// The implicit default is used.
Diagnostic::new(
AirflowDagNoScheduleArgument {
deprecated_argument: None,
},
expr.range(),
)
};
// Produce a diagnostic when the `schedule` keyword argument is not found.
let diagnostic = Diagnostic::new(AirflowDagNoScheduleArgument, expr.range());
checker.diagnostics.push(diagnostic);
}
Original file line number Diff line number Diff line change
@@ -1,54 +1,20 @@
---
source: crates/ruff_linter/src/rules/airflow/mod.rs
---
AIR301.py:4:1: AIR301 DAG should have an explicit `schedule` argument
AIR301.py:3:1: AIR301 DAG should have an explicit `schedule` argument
|
2 | from airflow.timetables.trigger import CronTriggerTimetable
3 |
4 | DAG(dag_id="class_default_schedule")
1 | from airflow import DAG, dag
2 |
3 | DAG(dag_id="class_default_schedule")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AIR301
5 |
6 | DAG(dag_id="class_schedule", schedule="@hourly")
4 |
5 | DAG(dag_id="class_schedule", schedule="@hourly")
|

AIR301.py:8:31: AIR301 argument `timetable` is deprecated; use `schedule` instead
AIR301.py:8:2: AIR301 DAG should have an explicit `schedule` argument
|
6 | DAG(dag_id="class_schedule", schedule="@hourly")
7 |
8 | DAG(dag_id="class_timetable", timetable=CronTriggerTimetable())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AIR301
9 |
10 | DAG(dag_id="class_schedule_interval", schedule_interval="@hourly")
|

AIR301.py:10:39: AIR301 argument `schedule_interval` is deprecated; use `schedule` instead
|
8 | DAG(dag_id="class_timetable", timetable=CronTriggerTimetable())
9 |
10 | DAG(dag_id="class_schedule_interval", schedule_interval="@hourly")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ AIR301
|

AIR301.py:13:2: AIR301 DAG should have an explicit `schedule` argument
|
13 | @dag()
8 | @dag()
| ^^^^^ AIR301
14 | def decorator_default_schedule():
15 | pass
|

AIR301.py:23:6: AIR301 argument `timetable` is deprecated; use `schedule` instead
|
23 | @dag(timetable=CronTriggerTimetable())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AIR301
24 | def decorator_timetable():
25 | pass
|

AIR301.py:28:6: AIR301 argument `schedule_interval` is deprecated; use `schedule` instead
|
28 | @dag(schedule_interval="0 * * * *")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AIR301
29 | def decorator_schedule_interval():
30 | pass
9 | def decorator_default_schedule():
10 | pass
|

0 comments on commit 83feee3

Please sign in to comment.