You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/01/08 03:09:01 UTC

[GitHub] [airflow] uranusjr commented on a change in pull request #20758: Avoid unintentional data loss when deleting DAGs

uranusjr commented on a change in pull request #20758:
URL: https://github.com/apache/airflow/pull/20758#discussion_r780624363



##########
File path: airflow/api/common/delete_dag.py
##########
@@ -54,6 +54,15 @@ def delete_dag(dag_id: str, keep_records_in_log: bool = True, session=None) -> i
     if dag is None:
         raise DagNotFound(f"Dag id {dag_id} not found")
 
+    # deleting a DAG should also all of its subdags
+    dags_to_delete = [
+        d[0]
+        for d in session.query(DagModel.dag_id)
+        .filter(and_(DagModel.dag_id.like(dag_id + ".%"), DagModel.is_subdag))
+        .all()
+    ]
+    dags_to_delete.append(dag_id)

Review comment:
       ```suggestion
       dags_to_delete_query = session.query(DagModel.dag_id).filter(
           or_(
               and_(DagModel.dag_id.like(f"{dag_id}.%"), DagModel.is_subdag),
               DagModel.dag_id == dag_id
           )
       )
       dags_to_delete = [dag_id for dag_id, in dags_to_delete_query]
   ```
   
   Would this be better?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org