Skip to content

Commit edce559

Browse files
authored
[airflow]: extend removed names (AIR302) (#14734)
1 parent 62e358e commit edce559

File tree

4 files changed

+265
-43
lines changed

4 files changed

+265
-43
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,52 @@
1+
from airflow.triggers.external_task import TaskStateTrigger
2+
from airflow.www.auth import has_access
3+
from airflow.api_connexion.security import requires_access
4+
from airflow.metrics.validators import AllowListValidator
5+
from airflow.metrics.validators import BlockListValidator
16
from airflow.utils import dates
2-
from airflow.utils.dates import date_range, datetime_to_nano, days_ago
7+
from airflow.utils.dates import (
8+
date_range,
9+
datetime_to_nano,
10+
days_ago,
11+
infer_time_unit,
12+
parse_execution_date,
13+
round_time,
14+
scale_time_units,
15+
)
16+
from airflow.utils.file import TemporaryDirectory, mkdirs
17+
from airflow.utils.state import SHUTDOWN, terminating_states
18+
from airflow.utils.dag_cycle_tester import test_cycle
19+
20+
21+
TaskStateTrigger
322

4-
date_range
5-
days_ago
23+
24+
has_access
25+
requires_access
26+
27+
AllowListValidator
28+
BlockListValidator
629

730
dates.date_range
831
dates.days_ago
932

33+
date_range
34+
days_ago
35+
parse_execution_date
36+
round_time
37+
scale_time_units
38+
infer_time_unit
39+
40+
1041
# This one was not deprecated.
1142
datetime_to_nano
1243
dates.datetime_to_nano
44+
45+
TemporaryDirectory
46+
mkdirs
47+
48+
SHUTDOWN
49+
terminating_states
50+
51+
52+
test_cycle

crates/ruff_linter/src/rules/airflow/rules/removal_in_3.rs

+65-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Violation for Airflow3Removal {
5151
match replacement {
5252
Replacement::None => format!("`{deprecated}` is removed in Airflow 3.0"),
5353
Replacement::Name(name) => {
54-
format!("`{deprecated}` is removed in Airflow 3.0; use {name} instead")
54+
format!("`{deprecated}` is removed in Airflow 3.0; use `{name}` instead")
5555
}
5656
}
5757
}
@@ -103,13 +103,75 @@ fn removed_name(checker: &mut Checker, expr: &Expr, ranged: impl Ranged) {
103103
.semantic()
104104
.resolve_qualified_name(expr)
105105
.and_then(|qualname| match qualname.segments() {
106-
["airflow", "utils", "dates", "date_range"] => {
106+
["airflow", "triggers", "external_task", "TaskStateTrigger"] => {
107107
Some((qualname.to_string(), Replacement::None))
108108
}
109+
["airflow", "www", "auth", "has_access"] => Some((
110+
qualname.to_string(),
111+
Replacement::Name("airflow.www.auth.has_access_*".to_string()),
112+
)),
113+
["airflow", "api_connexion", "security", "requires_access"] => Some((
114+
qualname.to_string(),
115+
Replacement::Name(
116+
"airflow.api_connexion.security.requires_access_*".to_string(),
117+
),
118+
)),
119+
// airflow.metrics.validators
120+
["airflow", "metrics", "validators", "AllowListValidator"] => Some((
121+
qualname.to_string(),
122+
Replacement::Name(
123+
"airflow.metrics.validators.PatternAllowListValidator".to_string(),
124+
),
125+
)),
126+
["airflow", "metrics", "validators", "BlockListValidator"] => Some((
127+
qualname.to_string(),
128+
Replacement::Name(
129+
"airflow.metrics.validators.PatternBlockListValidator".to_string(),
130+
),
131+
)),
132+
// airflow.utils.dates
133+
["airflow", "utils", "dates", "date_range"] => Some((
134+
qualname.to_string(),
135+
Replacement::Name("airflow.timetables.".to_string()),
136+
)),
109137
["airflow", "utils", "dates", "days_ago"] => Some((
110138
qualname.to_string(),
111-
Replacement::Name("datetime.timedelta()".to_string()),
139+
Replacement::Name("pendulum.today('UTC').add(days=-N, ...)".to_string()),
140+
)),
141+
["airflow", "utils", "dates", "parse_execution_date"] => {
142+
Some((qualname.to_string(), Replacement::None))
143+
}
144+
["airflow", "utils", "dates", "round_time"] => {
145+
Some((qualname.to_string(), Replacement::None))
146+
}
147+
["airflow", "utils", "dates", "scale_time_units"] => {
148+
Some((qualname.to_string(), Replacement::None))
149+
}
150+
["airflow", "utils", "dates", "infer_time_unit"] => {
151+
Some((qualname.to_string(), Replacement::None))
152+
}
153+
// airflow.utils.file
154+
["airflow", "utils", "file", "TemporaryDirectory"] => {
155+
Some((qualname.to_string(), Replacement::None))
156+
}
157+
["airflow", "utils", "file", "mkdirs"] => Some((
158+
qualname.to_string(),
159+
Replacement::Name("pendulum.today('UTC').add(days=-N, ...)".to_string()),
112160
)),
161+
// airflow.utils.state
162+
["airflow", "utils", "state", "SHUTDOWN"] => {
163+
Some((qualname.to_string(), Replacement::None))
164+
}
165+
["airflow", "utils", "state", "terminating_states"] => {
166+
Some((qualname.to_string(), Replacement::None))
167+
}
168+
// airflow.uilts
169+
["airflow", "utils", "dag_cycle_tester", "test_cycle"] => {
170+
Some((qualname.to_string(), Replacement::None))
171+
}
172+
["airflow", "utils", "decorators", "apply_defaults"] => {
173+
Some((qualname.to_string(), Replacement::None))
174+
}
113175
_ => None,
114176
});
115177
if let Some((deprecated, replacement)) = result {

crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR302_AIR302_args.py.snap

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
22
source: crates/ruff_linter/src/rules/airflow/mod.rs
3+
snapshot_kind: text
34
---
4-
AIR302_args.py:6:39: AIR302 `schedule_interval` is removed in Airflow 3.0; use schedule instead
5+
AIR302_args.py:6:39: AIR302 `schedule_interval` is removed in Airflow 3.0; use `schedule` instead
56
|
67
4 | DAG(dag_id="class_schedule", schedule="@hourly")
78
5 |
@@ -11,23 +12,23 @@ AIR302_args.py:6:39: AIR302 `schedule_interval` is removed in Airflow 3.0; use s
1112
8 | DAG(dag_id="class_timetable", timetable=NullTimetable())
1213
|
1314

14-
AIR302_args.py:8:31: AIR302 `timetable` is removed in Airflow 3.0; use schedule instead
15+
AIR302_args.py:8:31: AIR302 `timetable` is removed in Airflow 3.0; use `schedule` instead
1516
|
1617
6 | DAG(dag_id="class_schedule_interval", schedule_interval="@hourly")
1718
7 |
1819
8 | DAG(dag_id="class_timetable", timetable=NullTimetable())
1920
| ^^^^^^^^^ AIR302
2021
|
2122

22-
AIR302_args.py:16:6: AIR302 `schedule_interval` is removed in Airflow 3.0; use schedule instead
23+
AIR302_args.py:16:6: AIR302 `schedule_interval` is removed in Airflow 3.0; use `schedule` instead
2324
|
2425
16 | @dag(schedule_interval="0 * * * *")
2526
| ^^^^^^^^^^^^^^^^^ AIR302
2627
17 | def decorator_schedule_interval():
2728
18 | pass
2829
|
2930

30-
AIR302_args.py:21:6: AIR302 `timetable` is removed in Airflow 3.0; use schedule instead
31+
AIR302_args.py:21:6: AIR302 `timetable` is removed in Airflow 3.0; use `schedule` instead
3132
|
3233
21 | @dag(timetable=NullTimetable())
3334
| ^^^^^^^^^ AIR302
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,157 @@
11
---
22
source: crates/ruff_linter/src/rules/airflow/mod.rs
3+
snapshot_kind: text
34
---
4-
AIR302_names.py:4:1: AIR302 `airflow.utils.dates.date_range` is removed in Airflow 3.0
5-
|
6-
2 | from airflow.utils.dates import date_range, datetime_to_nano, days_ago
7-
3 |
8-
4 | date_range
9-
| ^^^^^^^^^^ AIR302
10-
5 | days_ago
11-
|
12-
13-
AIR302_names.py:5:1: AIR302 `airflow.utils.dates.days_ago` is removed in Airflow 3.0; use datetime.timedelta() instead
14-
|
15-
4 | date_range
16-
5 | days_ago
17-
| ^^^^^^^^ AIR302
18-
6 |
19-
7 | dates.date_range
20-
|
21-
22-
AIR302_names.py:7:7: AIR302 `airflow.utils.dates.date_range` is removed in Airflow 3.0
23-
|
24-
5 | days_ago
25-
6 |
26-
7 | dates.date_range
27-
| ^^^^^^^^^^ AIR302
28-
8 | dates.days_ago
29-
|
30-
31-
AIR302_names.py:8:7: AIR302 `airflow.utils.dates.days_ago` is removed in Airflow 3.0; use datetime.timedelta() instead
32-
|
33-
7 | dates.date_range
34-
8 | dates.days_ago
5+
AIR302_names.py:21:1: AIR302 `airflow.triggers.external_task.TaskStateTrigger` is removed in Airflow 3.0
6+
|
7+
21 | TaskStateTrigger
8+
| ^^^^^^^^^^^^^^^^ AIR302
9+
|
10+
11+
AIR302_names.py:24:1: AIR302 `airflow.www.auth.has_access` is removed in Airflow 3.0; use `airflow.www.auth.has_access_*` instead
12+
|
13+
24 | has_access
14+
| ^^^^^^^^^^ AIR302
15+
25 | requires_access
16+
|
17+
18+
AIR302_names.py:25:1: AIR302 `airflow.api_connexion.security.requires_access` is removed in Airflow 3.0; use `airflow.api_connexion.security.requires_access_*` instead
19+
|
20+
24 | has_access
21+
25 | requires_access
22+
| ^^^^^^^^^^^^^^^ AIR302
23+
26 |
24+
27 | AllowListValidator
25+
|
26+
27+
AIR302_names.py:27:1: AIR302 `airflow.metrics.validators.AllowListValidator` is removed in Airflow 3.0; use `airflow.metrics.validators.PatternAllowListValidator` instead
28+
|
29+
25 | requires_access
30+
26 |
31+
27 | AllowListValidator
32+
| ^^^^^^^^^^^^^^^^^^ AIR302
33+
28 | BlockListValidator
34+
|
35+
36+
AIR302_names.py:28:1: AIR302 `airflow.metrics.validators.BlockListValidator` is removed in Airflow 3.0; use `airflow.metrics.validators.PatternBlockListValidator` instead
37+
|
38+
27 | AllowListValidator
39+
28 | BlockListValidator
40+
| ^^^^^^^^^^^^^^^^^^ AIR302
41+
29 |
42+
30 | dates.date_range
43+
|
44+
45+
AIR302_names.py:30:7: AIR302 `airflow.utils.dates.date_range` is removed in Airflow 3.0; use `airflow.timetables.` instead
46+
|
47+
28 | BlockListValidator
48+
29 |
49+
30 | dates.date_range
50+
| ^^^^^^^^^^ AIR302
51+
31 | dates.days_ago
52+
|
53+
54+
AIR302_names.py:31:7: AIR302 `airflow.utils.dates.days_ago` is removed in Airflow 3.0; use `pendulum.today('UTC').add(days=-N, ...)` instead
55+
|
56+
30 | dates.date_range
57+
31 | dates.days_ago
3558
| ^^^^^^^^ AIR302
36-
9 |
37-
10 | # This one was not deprecated.
59+
32 |
60+
33 | date_range
61+
|
62+
63+
AIR302_names.py:33:1: AIR302 `airflow.utils.dates.date_range` is removed in Airflow 3.0; use `airflow.timetables.` instead
64+
|
65+
31 | dates.days_ago
66+
32 |
67+
33 | date_range
68+
| ^^^^^^^^^^ AIR302
69+
34 | days_ago
70+
35 | parse_execution_date
71+
|
72+
73+
AIR302_names.py:34:1: AIR302 `airflow.utils.dates.days_ago` is removed in Airflow 3.0; use `pendulum.today('UTC').add(days=-N, ...)` instead
74+
|
75+
33 | date_range
76+
34 | days_ago
77+
| ^^^^^^^^ AIR302
78+
35 | parse_execution_date
79+
36 | round_time
80+
|
81+
82+
AIR302_names.py:35:1: AIR302 `airflow.utils.dates.parse_execution_date` is removed in Airflow 3.0
83+
|
84+
33 | date_range
85+
34 | days_ago
86+
35 | parse_execution_date
87+
| ^^^^^^^^^^^^^^^^^^^^ AIR302
88+
36 | round_time
89+
37 | scale_time_units
90+
|
91+
92+
AIR302_names.py:36:1: AIR302 `airflow.utils.dates.round_time` is removed in Airflow 3.0
93+
|
94+
34 | days_ago
95+
35 | parse_execution_date
96+
36 | round_time
97+
| ^^^^^^^^^^ AIR302
98+
37 | scale_time_units
99+
38 | infer_time_unit
100+
|
101+
102+
AIR302_names.py:37:1: AIR302 `airflow.utils.dates.scale_time_units` is removed in Airflow 3.0
103+
|
104+
35 | parse_execution_date
105+
36 | round_time
106+
37 | scale_time_units
107+
| ^^^^^^^^^^^^^^^^ AIR302
108+
38 | infer_time_unit
109+
|
110+
111+
AIR302_names.py:38:1: AIR302 `airflow.utils.dates.infer_time_unit` is removed in Airflow 3.0
112+
|
113+
36 | round_time
114+
37 | scale_time_units
115+
38 | infer_time_unit
116+
| ^^^^^^^^^^^^^^^ AIR302
117+
|
118+
119+
AIR302_names.py:45:1: AIR302 `airflow.utils.file.TemporaryDirectory` is removed in Airflow 3.0
120+
|
121+
43 | dates.datetime_to_nano
122+
44 |
123+
45 | TemporaryDirectory
124+
| ^^^^^^^^^^^^^^^^^^ AIR302
125+
46 | mkdirs
126+
|
127+
128+
AIR302_names.py:46:1: AIR302 `airflow.utils.file.mkdirs` is removed in Airflow 3.0; use `pendulum.today('UTC').add(days=-N, ...)` instead
129+
|
130+
45 | TemporaryDirectory
131+
46 | mkdirs
132+
| ^^^^^^ AIR302
133+
47 |
134+
48 | SHUTDOWN
135+
|
136+
137+
AIR302_names.py:48:1: AIR302 `airflow.utils.state.SHUTDOWN` is removed in Airflow 3.0
138+
|
139+
46 | mkdirs
140+
47 |
141+
48 | SHUTDOWN
142+
| ^^^^^^^^ AIR302
143+
49 | terminating_states
144+
|
145+
146+
AIR302_names.py:49:1: AIR302 `airflow.utils.state.terminating_states` is removed in Airflow 3.0
147+
|
148+
48 | SHUTDOWN
149+
49 | terminating_states
150+
| ^^^^^^^^^^^^^^^^^^ AIR302
151+
|
152+
153+
AIR302_names.py:52:1: AIR302 `airflow.utils.dag_cycle_tester.test_cycle` is removed in Airflow 3.0
154+
|
155+
52 | test_cycle
156+
| ^^^^^^^^^^ AIR302
38157
|

0 commit comments

Comments
 (0)