[ 
https://issues.apache.org/jira/browse/AIRFLOW-1002?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16428874#comment-16428874
 ] 

Kyle Hamlin commented on AIRFLOW-1002:
--------------------------------------

I think there is still a bit of missing functionality for this feature. When 
the Flask app is created sessions are attached to each of the models but 
DagModel doesn't have a session attached to it. If you try to call delete_dag 
from a CeleryExecutor you get a sqlalchemy.orm.exc.DetachedInstanceError

 
{code:java}
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/airflow/utils/cli.py", line 72, in 
wrapper
raise e
File "/usr/local/lib/python3.6/site-packages/airflow/utils/cli.py", line 69, in 
wrapper
return f(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/airflow/bin/cli.py", line 226, in 
delete_dag
message = api_client.delete_dag(dag_id=args.dag_id)
File 
"/usr/local/lib/python3.6/site-packages/airflow/api/client/local_client.py", 
line 32, in delete_dag
count = delete_dag.delete_dag(dag_id)
File 
"/usr/local/lib/python3.6/site-packages/airflow/api/common/experimental/delete_dag.py",
 line 48, in delete_dag
if dag.is_subdag:
File "/usr/local/lib/python3.6/site-packages/sqlalchemy/orm/attributes.py", 
line 237, in __get__
return self.impl.get(instance_state(instance), dict_)
File "/usr/local/lib/python3.6/site-packages/sqlalchemy/orm/attributes.py", 
line 579, in get
value = state._load_expired(state, passive)
File "/usr/local/lib/python3.6/site-packages/sqlalchemy/orm/state.py", line 
592, in _load_expired
self.manager.deferred_scalar_loader(self, toload)
File "/usr/local/lib/python3.6/site-packages/sqlalchemy/orm/loading.py", line 
659, in load_scalar_attributes
(state_str(state)))
sqlalchemy.orm.exc.DetachedInstanceError: Instance <DagModel at 0x7f34572410f0> 
is not bound to a Session; attribute refresh operation cannot proceed{code}

> Add ability to remove DAG and all dependencies 
> -----------------------------------------------
>
>                 Key: AIRFLOW-1002
>                 URL: https://issues.apache.org/jira/browse/AIRFLOW-1002
>             Project: Apache Airflow
>          Issue Type: New Feature
>          Components: core, DAG
>    Affects Versions: Airflow 2.0, Airflow 1.8
>            Reporter: Ruslan Dautkhanov
>            Assignee: Kengo Seki
>            Priority: Major
>             Fix For: 2.0.0
>
>
> I don't see an obvious way to remove a DAG with dependencies
> Looks like folks have custom scripts to clean up backend database directly.
> http://stackoverflow.com/questions/40651783/airflow-how-to-delete-a-dag
> https://groups.google.com/forum/#!topic/airbnb_airflow/GVsNsUxPRC0
> It would be nice to have a feature to remove a DAG directly in UI / through 
> API.
> {code}
> queries = {'delete from xcom where dag_id = "' + dag_input + '"',
>         'delete from task_instance where dag_id = "' + dag_input + '"',
>         'delete from sla_miss where dag_id = "' + dag_input + '"',
>         'delete from log where dag_id = "' + dag_input + '"',
>         'delete from job where dag_id = "' + dag_input + '"',
>         'delete from dag_run where dag_id = "' + dag_input + '"',
>         'delete from dag where dag_id = "' + dag_input + '"' }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to