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

potiuk 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 13a558d  Add cascade to DagRun/TaskInstance relationship (#18434)
13a558d is described below

commit 13a558d658c3a1f6df4b2ee5d894fee65dc103db
Author: Ephraim Anierobi <[email protected]>
AuthorDate: Wed Sep 22 17:52:47 2021 +0100

    Add cascade to DagRun/TaskInstance relationship (#18434)
    
    * Add cascade to DagRun/TaskInstance relationship
    
    We currently have issue where deleting dagruns causes a dependency error in 
Sqlalchemy because
    the session doesn't know what to do with the related taskinstances.
    
    This PR adds cascade so that when a dagrun is marked for deletion, the 
related taskinstances
    are also deleted
---
 airflow/models/dagrun.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/airflow/models/dagrun.py b/airflow/models/dagrun.py
index e805ead..3d50b05 100644
--- a/airflow/models/dagrun.py
+++ b/airflow/models/dagrun.py
@@ -124,7 +124,9 @@ class DagRun(Base, LoggingMixin):
         ),
     )
 
-    task_instances = relationship(TI, back_populates="dag_run")
+    task_instances = relationship(
+        TI, back_populates="dag_run", cascade='save-update, merge, delete, 
delete-orphan'
+    )
 
     DEFAULT_DAGRUNS_TO_EXAMINE = airflow_conf.getint(
         'scheduler',

Reply via email to