Skip to content

Commit d8a5b9d

Browse files
authored
[airflow] Revise fix title AIR3 (#18215)
1 parent c3feb8c commit d8a5b9d

File tree

34 files changed

+290
-436
lines changed

34 files changed

+290
-436
lines changed

crates/ruff_linter/resources/test/fixtures/airflow/AIR302_common_sql.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,11 @@
114114
SqlSensor()
115115

116116

117-
from airflow.operators.jdbc_operator import JdbcOperator
118-
from airflow.operators.mssql_operator import MsSqlOperator
119-
from airflow.operators.mysql_operator import MySqlOperator
120-
from airflow.operators.oracle_operator import OracleOperator
121-
from airflow.operators.postgres_operator import PostgresOperator
122-
from airflow.operators.sqlite_operator import SqliteOperator
123-
124-
JdbcOperator()
125-
MsSqlOperator()
126-
MySqlOperator()
127-
OracleOperator()
128-
PostgresOperator()
129-
SqliteOperator()
117+
from airflow.providers.common.sql.operators.sql import SQLExecuteQueryOperator
118+
119+
SQLExecuteQueryOperator()
120+
SQLExecuteQueryOperator()
121+
SQLExecuteQueryOperator()
122+
SQLExecuteQueryOperator()
123+
SQLExecuteQueryOperator()
124+
SQLExecuteQueryOperator()

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,26 @@ impl Violation for Airflow3MovedToProvider {
6565

6666
fn fix_title(&self) -> Option<String> {
6767
let Airflow3MovedToProvider { replacement, .. } = self;
68-
match replacement {
69-
ProviderReplacement::None => None,
68+
if let Some((module, name, provider, version)) = match &replacement {
7069
ProviderReplacement::AutoImport {
71-
name,
7270
module,
71+
name,
7372
provider,
7473
version,
75-
} => Some(format!(
76-
"Install `apache-airflow-providers-{provider}>={version}` and use `{module}.{name}` instead."
77-
)),
74+
} => Some((module, *name, provider, version)),
7875
ProviderReplacement::SourceModuleMovedToProvider {
79-
name,
8076
module,
77+
name,
8178
provider,
8279
version,
83-
} => Some(format!(
84-
"Install `apache-airflow-providers-{provider}>={version}` and use `{module}.{name}` instead."
85-
)),
80+
} => Some((module, name.as_str(), provider, version)),
81+
ProviderReplacement::None => None,
82+
} {
83+
Some(format!(
84+
"Install `apache-airflow-providers-{provider}>={version}` and use `{name}` from `{module}` instead."
85+
))
86+
} else {
87+
None
8688
}
8789
}
8890
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ impl Violation for Airflow3Removal {
7373
Replacement::AttrName(name) => Some(format!("Use `{name}` instead")),
7474
Replacement::Message(message) => Some((*message).to_string()),
7575
Replacement::AutoImport { module, name } => {
76-
Some(format!("Use `{module}.{name}` instead"))
76+
Some(format!("Use `{name}` from `{module}` instead."))
7777
}
7878
Replacement::SourceModuleMoved { module, name } => {
79-
Some(format!("Use `{module}.{name}` instead"))
79+
Some(format!("Use `{name}` from `{module}` instead."))
8080
}
8181
}
8282
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ impl Violation for Airflow3SuggestedToMoveToProvider {
7777
provider,
7878
version,
7979
} => Some(format!(
80-
"Install `apache-airflow-providers-{provider}>={version}` and use `{module}.{name}` instead."
80+
"Install `apache-airflow-providers-{provider}>={version}` and use `{name}` from `{module}` instead."
8181
)),
8282
ProviderReplacement::SourceModuleMovedToProvider {
8383
module,
8484
name,
8585
provider,
8686
version,
8787
} => Some(format!(
88-
"Install `apache-airflow-providers-{provider}>={version}` and use `{module}.{name}` instead."
88+
"Install `apache-airflow-providers-{provider}>={version}` and use `{name}` from `{module}` instead."
8989
)),
9090
}
9191
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ impl Violation for Airflow3SuggestedUpdate {
7272
Replacement::AttrName(name) => Some(format!("Use `{name}` instead")),
7373
Replacement::Message(message) => Some((*message).to_string()),
7474
Replacement::AutoImport { module, name } => {
75-
Some(format!("Use `{module}.{name}` instead"))
75+
Some(format!("Use `{name}` from `{module}` instead."))
7676
}
7777
Replacement::SourceModuleMoved { module, name } => {
78-
Some(format!("Use `{module}.{name}` instead"))
78+
Some(format!("Use `{name}` from `{module}` instead."))
7979
}
8080
}
8181
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ AIR301_class_attribute.py:42:6: AIR301 [*] `airflow.datasets.manager.DatasetMana
171171
43 | dm.register_dataset_change()
172172
44 | dm.create_datasets()
173173
|
174-
= help: Use `airflow.assets.manager.AssetManager` instead
174+
= help: Use `AssetManager` from `airflow.assets.manager` instead.
175175

176176
Safe fix
177177
19 19 | from airflow.providers_manager import ProvidersManager
@@ -302,7 +302,7 @@ AIR301_class_attribute.py:50:11: AIR301 [*] `airflow.lineage.hook.DatasetLineage
302302
| ^^^^^^^^^^^^^^^^^^ AIR301
303303
51 | dl_info.dataset
304304
|
305-
= help: Use `airflow.lineage.hook.AssetLineageInfo` instead
305+
= help: Use `AssetLineageInfo` from `airflow.lineage.hook` instead.
306306

307307
Safe fix
308308
9 9 | DatasetAny,

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ AIR301_names.py:60:1: AIR301 [*] `airflow.configuration.get` is removed in Airfl
8585
60 | get, getboolean, getfloat, getint, has_option, remove_option, as_dict, set
8686
| ^^^ AIR301
8787
|
88-
= help: Use `airflow.configuration.conf.get` instead
88+
= help: Use `conf.get` from `airflow.configuration` instead.
8989

9090
Safe fix
9191
19 19 | has_option,
@@ -111,7 +111,7 @@ AIR301_names.py:60:6: AIR301 [*] `airflow.configuration.getboolean` is removed i
111111
60 | get, getboolean, getfloat, getint, has_option, remove_option, as_dict, set
112112
| ^^^^^^^^^^ AIR301
113113
|
114-
= help: Use `airflow.configuration.conf.getboolean` instead
114+
= help: Use `conf.getboolean` from `airflow.configuration` instead.
115115

116116
Safe fix
117117
19 19 | has_option,
@@ -137,7 +137,7 @@ AIR301_names.py:60:18: AIR301 [*] `airflow.configuration.getfloat` is removed in
137137
60 | get, getboolean, getfloat, getint, has_option, remove_option, as_dict, set
138138
| ^^^^^^^^ AIR301
139139
|
140-
= help: Use `airflow.configuration.conf.getfloat` instead
140+
= help: Use `conf.getfloat` from `airflow.configuration` instead.
141141

142142
Safe fix
143143
19 19 | has_option,
@@ -163,7 +163,7 @@ AIR301_names.py:60:28: AIR301 [*] `airflow.configuration.getint` is removed in A
163163
60 | get, getboolean, getfloat, getint, has_option, remove_option, as_dict, set
164164
| ^^^^^^ AIR301
165165
|
166-
= help: Use `airflow.configuration.conf.getint` instead
166+
= help: Use `conf.getint` from `airflow.configuration` instead.
167167

168168
Safe fix
169169
19 19 | has_option,
@@ -189,7 +189,7 @@ AIR301_names.py:60:36: AIR301 [*] `airflow.configuration.has_option` is removed
189189
60 | get, getboolean, getfloat, getint, has_option, remove_option, as_dict, set
190190
| ^^^^^^^^^^ AIR301
191191
|
192-
= help: Use `airflow.configuration.conf.has_option` instead
192+
= help: Use `conf.has_option` from `airflow.configuration` instead.
193193

194194
Safe fix
195195
19 19 | has_option,
@@ -215,7 +215,7 @@ AIR301_names.py:60:48: AIR301 [*] `airflow.configuration.remove_option` is remov
215215
60 | get, getboolean, getfloat, getint, has_option, remove_option, as_dict, set
216216
| ^^^^^^^^^^^^^ AIR301
217217
|
218-
= help: Use `airflow.configuration.conf.remove_option` instead
218+
= help: Use `conf.remove_option` from `airflow.configuration` instead.
219219

220220
Safe fix
221221
19 19 | has_option,
@@ -241,7 +241,7 @@ AIR301_names.py:60:63: AIR301 [*] `airflow.configuration.as_dict` is removed in
241241
60 | get, getboolean, getfloat, getint, has_option, remove_option, as_dict, set
242242
| ^^^^^^^ AIR301
243243
|
244-
= help: Use `airflow.configuration.conf.as_dict` instead
244+
= help: Use `conf.as_dict` from `airflow.configuration` instead.
245245

246246
Safe fix
247247
19 19 | has_option,
@@ -267,7 +267,7 @@ AIR301_names.py:60:72: AIR301 [*] `airflow.configuration.set` is removed in Airf
267267
60 | get, getboolean, getfloat, getint, has_option, remove_option, as_dict, set
268268
| ^^^ AIR301
269269
|
270-
= help: Use `airflow.configuration.conf.set` instead
270+
= help: Use `conf.set` from `airflow.configuration` instead.
271271

272272
Safe fix
273273
19 19 | has_option,
@@ -308,7 +308,7 @@ AIR301_names.py:72:1: AIR301 `airflow.hooks.base_hook.BaseHook` is removed in Ai
308308
72 | BaseHook()
309309
| ^^^^^^^^ AIR301
310310
|
311-
= help: Use `airflow.hooks.base.BaseHook` instead
311+
= help: Use `BaseHook` from `airflow.hooks.base` instead.
312312

313313
AIR301_names.py:76:1: AIR301 `airflow.operators.subdag.SubDagOperator` is removed in Airflow 3.0
314314
|
@@ -324,7 +324,7 @@ AIR301_names.py:85:1: AIR301 `airflow.sensors.base_sensor_operator.BaseSensorOpe
324324
85 | BaseSensorOperator()
325325
| ^^^^^^^^^^^^^^^^^^ AIR301
326326
|
327-
= help: Use `airflow.sdk.bases.sensor.BaseSensorOperator` instead
327+
= help: Use `BaseSensorOperator` from `airflow.sdk.bases.sensor` instead.
328328

329329
AIR301_names.py:89:1: AIR301 `airflow.triggers.external_task.TaskStateTrigger` is removed in Airflow 3.0
330330
|
@@ -446,7 +446,7 @@ AIR301_names.py:117:1: AIR301 `airflow.utils.file.TemporaryDirectory` is removed
446446
| ^^^^^^^^^^^^^^^^^^ AIR301
447447
118 | mkdirs
448448
|
449-
= help: Use `tempfile.TemporaryDirectory` instead
449+
= help: Use `TemporaryDirectory` from `tempfile` instead.
450450

451451
AIR301_names.py:118:1: AIR301 `airflow.utils.file.mkdirs` is removed in Airflow 3.0
452452
|
@@ -466,7 +466,7 @@ AIR301_names.py:121:1: AIR301 [*] `airflow.utils.helpers.chain` is removed in Ai
466466
| ^^^^^^^^^^^^ AIR301
467467
122 | helper_cross_downstream
468468
|
469-
= help: Use `airflow.sdk.chain` instead
469+
= help: Use `chain` from `airflow.sdk` instead.
470470

471471
Safe fix
472472
48 48 | from airflow.utils.trigger_rule import TriggerRule
@@ -495,7 +495,7 @@ AIR301_names.py:122:1: AIR301 [*] `airflow.utils.helpers.cross_downstream` is re
495495
123 |
496496
124 | # airflow.utils.log
497497
|
498-
= help: Use `airflow.sdk.cross_downstream` instead
498+
= help: Use `cross_downstream` from `airflow.sdk` instead.
499499

500500
Safe fix
501501
48 48 | from airflow.utils.trigger_rule import TriggerRule
@@ -523,7 +523,7 @@ AIR301_names.py:125:1: AIR301 `airflow.utils.log.secrets_masker` is removed in A
523523
126 |
524524
127 | # airflow.utils.state
525525
|
526-
= help: Use `airflow.sdk.execution_time.secrets_masker` instead
526+
= help: Use `secrets_masker` from `airflow.sdk.execution_time` instead.
527527

528528
AIR301_names.py:128:1: AIR301 `airflow.utils.state.SHUTDOWN` is removed in Airflow 3.0
529529
|
@@ -595,7 +595,7 @@ AIR301_names.py:146:1: AIR301 `airflow.operators.python.get_current_context` is
595595
147 |
596596
148 | # airflow.providers.mysql
597597
|
598-
= help: Use `airflow.sdk.get_current_context` instead
598+
= help: Use `get_current_context` from `airflow.sdk` instead.
599599

600600
AIR301_names.py:151:1: AIR301 `airflow.providers.mysql.datasets.mysql.sanitize_uri` is removed in Airflow 3.0
601601
|
@@ -606,7 +606,7 @@ AIR301_names.py:151:1: AIR301 `airflow.providers.mysql.datasets.mysql.sanitize_u
606606
152 |
607607
153 | # airflow.providers.postgres
608608
|
609-
= help: Use `airflow.providers.mysql.assets.mysql.sanitize_uri` instead
609+
= help: Use `sanitize_uri` from `airflow.providers.mysql.assets.mysql` instead.
610610

611611
AIR301_names.py:156:1: AIR301 `airflow.providers.postgres.datasets.postgres.sanitize_uri` is removed in Airflow 3.0
612612
|
@@ -617,7 +617,7 @@ AIR301_names.py:156:1: AIR301 `airflow.providers.postgres.datasets.postgres.sani
617617
157 |
618618
158 | # airflow.providers.trino
619619
|
620-
= help: Use `airflow.providers.postgres.assets.postgres.sanitize_uri` instead
620+
= help: Use `sanitize_uri` from `airflow.providers.postgres.assets.postgres` instead.
621621

622622
AIR301_names.py:161:1: AIR301 `airflow.providers.trino.datasets.trino.sanitize_uri` is removed in Airflow 3.0
623623
|
@@ -628,7 +628,7 @@ AIR301_names.py:161:1: AIR301 `airflow.providers.trino.datasets.trino.sanitize_u
628628
162 |
629629
163 | # airflow.notifications.basenotifier
630630
|
631-
= help: Use `airflow.providers.trino.assets.trino.sanitize_uri` instead
631+
= help: Use `sanitize_uri` from `airflow.providers.trino.assets.trino` instead.
632632

633633
AIR301_names.py:166:1: AIR301 `airflow.notifications.basenotifier.BaseNotifier` is removed in Airflow 3.0
634634
|
@@ -639,7 +639,7 @@ AIR301_names.py:166:1: AIR301 `airflow.notifications.basenotifier.BaseNotifier`
639639
167 |
640640
168 | # airflow.auth.manager
641641
|
642-
= help: Use `airflow.sdk.bases.notifier.BaseNotifier` instead
642+
= help: Use `BaseNotifier` from `airflow.sdk.bases.notifier` instead.
643643

644644
AIR301_names.py:171:1: AIR301 `airflow.auth.managers.base_auth_manager.BaseAuthManager` is removed in Airflow 3.0
645645
|
@@ -648,4 +648,4 @@ AIR301_names.py:171:1: AIR301 `airflow.auth.managers.base_auth_manager.BaseAuthM
648648
171 | BaseAuthManager()
649649
| ^^^^^^^^^^^^^^^ AIR301
650650
|
651-
= help: Use `airflow.api_fastapi.auth.managers.base_auth_manager.BaseAuthManager` instead
651+
= help: Use `BaseAuthManager` from `airflow.api_fastapi.auth.managers.base_auth_manager` instead.

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ AIR301_names_fix.py:19:1: AIR301 [*] `airflow.api_connexion.security.requires_ac
1010
20 |
1111
21 | DatasetDetails()
1212
|
13-
= help: Use `airflow.api_fastapi.core_api.security.requires_access_asset` instead
13+
= help: Use `requires_access_asset` from `airflow.api_fastapi.core_api.security` instead.
1414

1515
Safe fix
1616
15 15 | from airflow.secrets.local_filesystm import load_connections
@@ -31,7 +31,7 @@ AIR301_names_fix.py:21:1: AIR301 [*] `airflow.auth.managers.models.resource_deta
3131
21 | DatasetDetails()
3232
| ^^^^^^^^^^^^^^ AIR301
3333
|
34-
= help: Use `airflow.api_fastapi.auth.managers.models.resource_details.AssetDetails` instead
34+
= help: Use `AssetDetails` from `airflow.api_fastapi.auth.managers.models.resource_details` instead.
3535

3636
Safe fix
3737
15 15 | from airflow.secrets.local_filesystm import load_connections
@@ -54,7 +54,7 @@ AIR301_names_fix.py:24:1: AIR301 [*] `airflow.datasets.manager.DatasetManager` i
5454
25 | dataset_manager()
5555
26 | resolve_dataset_manager()
5656
|
57-
= help: Use `airflow.assets.manager.AssetManager` instead
57+
= help: Use `AssetManager` from `airflow.assets.manager` instead.
5858

5959
Safe fix
6060
15 15 | from airflow.secrets.local_filesystm import load_connections
@@ -80,7 +80,7 @@ AIR301_names_fix.py:25:1: AIR301 [*] `airflow.datasets.manager.dataset_manager`
8080
| ^^^^^^^^^^^^^^^ AIR301
8181
26 | resolve_dataset_manager()
8282
|
83-
= help: Use `airflow.assets.manager.asset_manager` instead
83+
= help: Use `asset_manager` from `airflow.assets.manager` instead.
8484

8585
Safe fix
8686
15 15 | from airflow.secrets.local_filesystm import load_connections
@@ -109,7 +109,7 @@ AIR301_names_fix.py:26:1: AIR301 [*] `airflow.datasets.manager.resolve_dataset_m
109109
27 |
110110
28 | DatasetLineageInfo()
111111
|
112-
= help: Use `airflow.assets.manager.resolve_asset_manager` instead
112+
= help: Use `resolve_asset_manager` from `airflow.assets.manager` instead.
113113

114114
Safe fix
115115
15 15 | from airflow.secrets.local_filesystm import load_connections
@@ -138,7 +138,7 @@ AIR301_names_fix.py:28:1: AIR301 [*] `airflow.lineage.hook.DatasetLineageInfo` i
138138
29 |
139139
30 | AllowListValidator()
140140
|
141-
= help: Use `airflow.lineage.hook.AssetLineageInfo` instead
141+
= help: Use `AssetLineageInfo` from `airflow.lineage.hook` instead.
142142

143143
Safe fix
144144
10 10 | dataset_manager,
@@ -167,7 +167,7 @@ AIR301_names_fix.py:30:1: AIR301 [*] `airflow.metrics.validators.AllowListValida
167167
| ^^^^^^^^^^^^^^^^^^ AIR301
168168
31 | BlockListValidator()
169169
|
170-
= help: Use `airflow.metrics.validators.PatternAllowListValidator` instead
170+
= help: Use `PatternAllowListValidator` from `airflow.metrics.validators` instead.
171171

172172
Safe fix
173173
11 11 | resolve_dataset_manager,
@@ -196,7 +196,7 @@ AIR301_names_fix.py:31:1: AIR301 [*] `airflow.metrics.validators.BlockListValida
196196
32 |
197197
33 | load_connections()
198198
|
199-
= help: Use `airflow.metrics.validators.PatternBlockListValidator` instead
199+
= help: Use `PatternBlockListValidator` from `airflow.metrics.validators` instead.
200200

201201
Safe fix
202202
11 11 | resolve_dataset_manager,
@@ -226,7 +226,7 @@ AIR301_names_fix.py:35:1: AIR301 [*] `airflow.security.permissions.RESOURCE_DATA
226226
36 |
227227
37 | has_access_dataset()
228228
|
229-
= help: Use `airflow.security.permissions.RESOURCE_ASSET` instead
229+
= help: Use `RESOURCE_ASSET` from `airflow.security.permissions` instead.
230230

231231
Safe fix
232232
13 13 | from airflow.lineage.hook import DatasetLineageInfo
@@ -265,7 +265,7 @@ AIR301_names_fix.py:44:1: AIR301 [*] `airflow.listeners.spec.dataset.on_dataset_
265265
| ^^^^^^^^^^^^^^^^^^ AIR301
266266
45 | on_dataset_changed()
267267
|
268-
= help: Use `airflow.listeners.spec.asset.on_asset_created` instead
268+
= help: Use `on_asset_created` from `airflow.listeners.spec.asset` instead.
269269

270270
Safe fix
271271
40 40 | on_dataset_changed,
@@ -283,7 +283,7 @@ AIR301_names_fix.py:45:1: AIR301 [*] `airflow.listeners.spec.dataset.on_dataset_
283283
45 | on_dataset_changed()
284284
| ^^^^^^^^^^^^^^^^^^ AIR301
285285
|
286-
= help: Use `airflow.listeners.spec.asset.on_asset_changed` instead
286+
= help: Use `on_asset_changed` from `airflow.listeners.spec.asset` instead.
287287

288288
Safe fix
289289
40 40 | on_dataset_changed,

0 commit comments

Comments
 (0)