29
29
from airflow .decorators import task
30
30
from airflow .exceptions import AirflowException , AirflowSkipException
31
31
from airflow .models .renderedtifields import RenderedTaskInstanceFields
32
+ from airflow .sdk .definitions ._internal .types import SET_DURING_EXECUTION
32
33
from airflow .utils import timezone
33
- from airflow .utils .types import NOTSET
34
34
35
35
from tests_common .test_utils .db import clear_db_dags , clear_db_runs , clear_rendered_ti_fields
36
+ from tests_common .test_utils .version_compat import AIRFLOW_V_3_0_PLUS
36
37
37
38
if TYPE_CHECKING :
38
39
from airflow .models import TaskInstance
@@ -69,7 +70,10 @@ def execute_task(self, task):
69
70
70
71
@staticmethod
71
72
def validate_bash_command_rtif (ti , expected_command ):
72
- assert RenderedTaskInstanceFields .get_templated_fields (ti )["bash_command" ] == expected_command
73
+ if AIRFLOW_V_3_0_PLUS :
74
+ assert ti .task .overwrite_rtif_after_execution
75
+ else :
76
+ assert RenderedTaskInstanceFields .get_templated_fields (ti )["bash_command" ] == expected_command
73
77
74
78
def test_bash_decorator_init (self ):
75
79
"""Test the initialization of the @task.bash decorator."""
@@ -81,13 +85,13 @@ def bash(): ...
81
85
bash_task = bash ()
82
86
83
87
assert bash_task .operator .task_id == "bash"
84
- assert bash_task .operator .bash_command == NOTSET
88
+ assert bash_task .operator .bash_command == SET_DURING_EXECUTION
85
89
assert bash_task .operator .env is None
86
90
assert bash_task .operator .append_env is False
87
91
assert bash_task .operator .output_encoding == "utf-8"
88
92
assert bash_task .operator .skip_on_exit_code == [99 ]
89
93
assert bash_task .operator .cwd is None
90
- assert bash_task .operator ._init_bash_command_not_set is True
94
+ assert bash_task .operator ._is_inline_cmd is None
91
95
92
96
@pytest .mark .parametrize (
93
97
argnames = ["command" , "expected_command" , "expected_return_val" ],
@@ -108,13 +112,12 @@ def bash():
108
112
109
113
bash_task = bash ()
110
114
111
- assert bash_task .operator .bash_command == NOTSET
115
+ assert bash_task .operator .bash_command == SET_DURING_EXECUTION
112
116
113
117
ti , return_val = self .execute_task (bash_task )
114
118
115
119
assert bash_task .operator .bash_command == expected_command
116
120
assert return_val == expected_return_val
117
-
118
121
self .validate_bash_command_rtif (ti , expected_command )
119
122
120
123
def test_op_args_kwargs (self ):
@@ -127,7 +130,7 @@ def bash(id, other_id):
127
130
128
131
bash_task = bash ("world" , other_id = "2" )
129
132
130
- assert bash_task .operator .bash_command == NOTSET
133
+ assert bash_task .operator .bash_command == SET_DURING_EXECUTION
131
134
132
135
ti , return_val = self .execute_task (bash_task )
133
136
@@ -152,7 +155,7 @@ def bash(foo):
152
155
153
156
bash_task = bash ("foo" )
154
157
155
- assert bash_task .operator .bash_command == NOTSET
158
+ assert bash_task .operator .bash_command == SET_DURING_EXECUTION
156
159
157
160
ti , return_val = self .execute_task (bash_task )
158
161
@@ -178,7 +181,7 @@ def bash():
178
181
179
182
bash_task = bash ()
180
183
181
- assert bash_task .operator .bash_command == NOTSET
184
+ assert bash_task .operator .bash_command == SET_DURING_EXECUTION
182
185
183
186
with mock .patch .dict ("os.environ" , {"AIRFLOW_HOME" : "path/to/airflow/home" }):
184
187
ti , return_val = self .execute_task (bash_task )
@@ -207,7 +210,7 @@ def bash(code):
207
210
208
211
bash_task = bash (exit_code )
209
212
210
- assert bash_task .operator .bash_command == NOTSET
213
+ assert bash_task .operator .bash_command == SET_DURING_EXECUTION
211
214
212
215
with expected :
213
216
ti , return_val = self .execute_task (bash_task )
@@ -251,7 +254,7 @@ def bash(code):
251
254
252
255
bash_task = bash (exit_code )
253
256
254
- assert bash_task .operator .bash_command == NOTSET
257
+ assert bash_task .operator .bash_command == SET_DURING_EXECUTION
255
258
256
259
with expected :
257
260
ti , return_val = self .execute_task (bash_task )
@@ -297,7 +300,7 @@ def bash(command_file_name):
297
300
with mock .patch .dict ("os.environ" , {"AIRFLOW_HOME" : "path/to/airflow/home" }):
298
301
bash_task = bash (f"{ cmd_file } " )
299
302
300
- assert bash_task .operator .bash_command == NOTSET
303
+ assert bash_task .operator .bash_command == SET_DURING_EXECUTION
301
304
302
305
ti , return_val = self .execute_task (bash_task )
303
306
@@ -319,7 +322,7 @@ def bash():
319
322
320
323
bash_task = bash ()
321
324
322
- assert bash_task .operator .bash_command == NOTSET
325
+ assert bash_task .operator .bash_command == SET_DURING_EXECUTION
323
326
324
327
ti , return_val = self .execute_task (bash_task )
325
328
@@ -339,7 +342,7 @@ def bash():
339
342
340
343
bash_task = bash ()
341
344
342
- assert bash_task .operator .bash_command == NOTSET
345
+ assert bash_task .operator .bash_command == SET_DURING_EXECUTION
343
346
344
347
dr = self .dag_maker .create_dagrun ()
345
348
ti = dr .task_instances [0 ]
@@ -360,7 +363,7 @@ def bash():
360
363
361
364
bash_task = bash ()
362
365
363
- assert bash_task .operator .bash_command == NOTSET
366
+ assert bash_task .operator .bash_command == SET_DURING_EXECUTION
364
367
365
368
dr = self .dag_maker .create_dagrun ()
366
369
ti = dr .task_instances [0 ]
@@ -378,7 +381,7 @@ def bash():
378
381
379
382
bash_task = bash ()
380
383
381
- assert bash_task .operator .bash_command == NOTSET
384
+ assert bash_task .operator .bash_command == SET_DURING_EXECUTION
382
385
383
386
dr = self .dag_maker .create_dagrun ()
384
387
ti = dr .task_instances [0 ]
@@ -401,20 +404,21 @@ def bash():
401
404
):
402
405
bash_task = bash ()
403
406
404
- assert bash_task .operator .bash_command == NOTSET
407
+ assert bash_task .operator .bash_command == SET_DURING_EXECUTION
405
408
406
409
ti , _ = self .execute_task (bash_task )
407
410
408
411
assert bash_task .operator .multiple_outputs is False
409
412
self .validate_bash_command_rtif (ti , "echo" )
410
413
411
414
@pytest .mark .parametrize (
412
- "multiple_outputs" , [False , pytest .param (None , id = "none" ), pytest .param (NOTSET , id = "not-set" )]
415
+ "multiple_outputs" ,
416
+ [False , pytest .param (None , id = "none" ), pytest .param (SET_DURING_EXECUTION , id = "not-set" )],
413
417
)
414
418
def test_multiple_outputs (self , multiple_outputs ):
415
419
"""Verify setting `multiple_outputs` for a @task.bash-decorated function is ignored."""
416
420
decorator_kwargs = {}
417
- if multiple_outputs is not NOTSET :
421
+ if multiple_outputs is not SET_DURING_EXECUTION :
418
422
decorator_kwargs ["multiple_outputs" ] = multiple_outputs
419
423
420
424
with self .dag :
@@ -428,7 +432,7 @@ def bash():
428
432
429
433
bash_task = bash ()
430
434
431
- assert bash_task .operator .bash_command == NOTSET
435
+ assert bash_task .operator .bash_command == SET_DURING_EXECUTION
432
436
433
437
ti , _ = self .execute_task (bash_task )
434
438
@@ -440,7 +444,9 @@ def bash():
440
444
argvalues = [
441
445
pytest .param (None , pytest .raises (TypeError ), id = "return_none_typeerror" ),
442
446
pytest .param (1 , pytest .raises (TypeError ), id = "return_int_typeerror" ),
443
- pytest .param (NOTSET , pytest .raises (TypeError ), id = "return_notset_typeerror" ),
447
+ pytest .param (
448
+ SET_DURING_EXECUTION , pytest .raises (TypeError ), id = "return_SET_DURING_EXECUTION_typeerror"
449
+ ),
444
450
pytest .param (True , pytest .raises (TypeError ), id = "return_boolean_typeerror" ),
445
451
pytest .param ("" , pytest .raises (TypeError ), id = "return_empty_string_typerror" ),
446
452
pytest .param (" " , pytest .raises (TypeError ), id = "return_spaces_string_typerror" ),
@@ -458,7 +464,7 @@ def bash():
458
464
459
465
bash_task = bash ()
460
466
461
- assert bash_task .operator .bash_command == NOTSET
467
+ assert bash_task .operator .bash_command == SET_DURING_EXECUTION
462
468
463
469
with expected :
464
470
ti , _ = self .execute_task (bash_task )
@@ -475,7 +481,7 @@ def bash():
475
481
476
482
bash_task = bash ()
477
483
478
- assert bash_task .operator .bash_command == NOTSET
484
+ assert bash_task .operator .bash_command == SET_DURING_EXECUTION
479
485
480
486
dr = self .dag_maker .create_dagrun ()
481
487
ti = dr .task_instances [0 ]
0 commit comments