This is an automated email from the ASF dual-hosted git repository.

ephraimanierobi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new cb18d923f8 Retain on_failure_fail_dagrun attr when other task attrs 
are overriden (#31678)
cb18d923f8 is described below

commit cb18d923f8253ac257c1b47e9276c39bae967666
Author: Ephraim Anierobi <[email protected]>
AuthorDate: Fri Jun 2 14:52:52 2023 +0100

    Retain on_failure_fail_dagrun attr when other task attrs are overriden 
(#31678)
    
    When on_failure_fail_dagrun is True on a task and we override other
    attributes of a task using task.override, we should still retain the
    value of on_failure_fail_dagrun. This needs special treatment since
    it's not original task param.
---
 airflow/decorators/base.py              |  1 +
 tests/decorators/test_setup_teardown.py | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/airflow/decorators/base.py b/airflow/decorators/base.py
index 81943b3907..df890c036d 100644
--- a/airflow/decorators/base.py
+++ b/airflow/decorators/base.py
@@ -488,6 +488,7 @@ class _TaskDecorator(ExpandableFactory, Generic[FParams, 
FReturn, OperatorSubcla
         result = attr.evolve(self, kwargs={**self.kwargs, **kwargs})
         setattr(result, "is_setup", self.is_setup)
         setattr(result, "is_teardown", self.is_teardown)
+        setattr(result, "on_failure_fail_dagrun", self.on_failure_fail_dagrun)
         return result
 
 
diff --git a/tests/decorators/test_setup_teardown.py 
b/tests/decorators/test_setup_teardown.py
index 4e4b8ed54f..d91f7fac53 100644
--- a/tests/decorators/test_setup_teardown.py
+++ b/tests/decorators/test_setup_teardown.py
@@ -180,6 +180,18 @@ class TestSetupTearDownTask:
         assert teardown_task.is_teardown
         assert teardown_task.on_failure_fail_dagrun
 
+    def 
test_retain_on_failure_fail_dagrun_when_other_attrs_are_overriden(self, 
dag_maker):
+        @teardown(on_failure_fail_dagrun=True)
+        def mytask():
+            print("I am a teardown task")
+
+        with dag_maker() as dag:
+            mytask.override(task_id="mytask2")()
+        assert len(dag.task_group.children) == 1
+        teardown_task = dag.task_group.children["mytask2"]
+        assert teardown_task.is_teardown
+        assert teardown_task.on_failure_fail_dagrun
+
     def test_setup_teardown_mixed_up_in_a_dag(self, dag_maker):
         @setup
         def setuptask():

Reply via email to