question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot delete DAG with Tags from UI

See original GitHub issue

Apache Airflow version

2.3.1 (latest released)

What happened

When deleting a DAG, which has tags from the home page, I receive and error. The error comes from not being able to delete the dag_id from the dag_tag table.

What you think should happen instead

DAG should be removed from dag_tag table and then removed from dag table

How to reproduce

Create a DAG with tags, deploy it to Airflow, and run it. After the DAG run has been completed, try to delete it.

Operating System

Ubuntu 20.04.4 LTS

Versions of Apache Airflow Providers

apache-airflow                     @ file: /home/airflow/deploy/apache_airflow-2.3.1-py3-none-any.whl
apache-airflow-providers-amazon    @ file: /home/airflow/deploy/apache_airflow_providers_amazon-3.4.0-py3-none-any.whl
apache-airflow-providers-ftp       @ file: /home/airflow/deploy/apache_airflow_providers_ftp-2.1.2-py3-none-any.whl
apache-airflow-providers-http      @ file: /home/airflow/deploy/apache_airflow_providers_http-2.1.2-py3-none-any.whl
apache-airflow-providers-imap      @ file: /home/airflow/deploy/apache_airflow_providers_imap-2.2.3-py3-none-any.whl
apache-airflow-providers-mongo     @ file: /home/airflow/deploy/apache_airflow_providers_mongo-2.3.3-py3-none-any.whl
apache-airflow-providers-mysql     @ file: /home/airflow/deploy/apache_airflow_providers_mysql-2.2.3-py3-none-any.whl
apache-airflow-providers-pagerduty @ file: /home/airflow/deploy/apache_airflow_providers_pagerduty-2.1.3-py3-none-any.whl
apache-airflow-providers-postgres  @ file: /home/airflow/deploy/apache_airflow_providers_postgres-4.1.0-py3-none-any.whl
apache-airflow-providers-redis     @ file: /home/airflow/deploy/apache_airflow_providers_redis-2.0.4-py3-none-any.whl
apache-airflow-providers-sendgrid  @ file: /home/airflow/deploy/apache_airflow_providers_sendgrid-2.0.4-py3-none-any.whl
apache-airflow-providers-slack     @ file: /home/airflow/deploy/apache_airflow_providers_slack-4.2.3-py3-none-any.whl
apache-airflow-providers-sqlite    @ file: /home/airflow/deploy/apache_airflow_providers_sqlite-2.1.3-py3-none-any.whl
apache-airflow-providers-ssh       @ file: /home/airflow/deploy/apache_airflow_providers_ssh-2.4.4-py3-none-any.whl
apache-airflow-providers-vertica   @ file: /home/airflow/deploy/apache_airflow_providers_vertica-2.1.3-py3-none-any.whl

Deployment

Virtualenv installation

Deployment details

python 3.8

Anything else

The following error occurs in the airflow-webserver backend:

[2022-06-02 11:26:55,290] {app.py:1891} ERROR - Exception on /delete [POST]
Traceback (most recent call last):
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1705, in _execute_context
    self.dialect.do_execute(
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 716, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.ForeignKeyViolation: update or delete on table "dag" violates foreign key constraint "dag_tag_dag_id_fkey" on table "dag_tag"
DETAIL:  Key (dag_id)=(subscription_attribution) is still referenced from table "dag_tag".


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/airflow/www/auth.py", line 43, in decorated
    return func(*args, **kwargs)
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/airflow/www/decorators.py", line 80, in wrapper
    return f(*args, **kwargs)
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/airflow/www/views.py", line 1844, in delete
    delete_dag.delete_dag(dag_id)
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/airflow/utils/session.py", line 71, in wrapper
    return func(*args, session=session, **kwargs)
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/airflow/api/common/delete_dag.py", line 78, in delete_dag
    session.query(model)
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3108, in delete
    result = self.session.execute(
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 1670, in execute
    result = conn._execute_20(statement, params or {}, execution_options)
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1520, in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 313, in _execute_on_connection
    return connection._execute_clauseelement(
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1389, in _execute_clauseelement
    ret = self._execute_context(
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1748, in _execute_context
    self._handle_dbapi_exception(
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1929, in _handle_dbapi_exception
    util.raise_(
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1705, in _execute_context
    self.dialect.do_execute(
  File "/home/airflow/venv/airflow-2180@1654168481/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 716, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.ForeignKeyViolation) update or delete on table "dag" violates foreign key constraint "dag_tag_dag_id_fkey" on table "dag_tag"
DETAIL:  Key (dag_id)=(subscription_attribution) is still referenced from table "dag_tag".

[SQL: DELETE FROM dag WHERE dag.dag_id IN (%(dag_id_1_1)s) RETURNING dag.dag_id]
[parameters: {'dag_id_1_1': 'subscription_attribution'}]
(Background on this error at: http://sqlalche.me/e/14/gkpj)

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rotemseekingalphacommented, Jun 2, 2022

@eladkal verified as working in 2.3.2rc2

0reactions
eladkalcommented, Jun 2, 2022

Great! closing then

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't delete dag from airflow UI after deleting from dag_bag
Try stopping the scheduler and the webserver and then deleting the DAG from the command line: airflow delete_dag 'MY_DAG_ID'.
Read more >
1472710 - Remove old inactive dags from airflow dag list UI
It shows up in this list because the scheduler marked it as active in the metadata database." We should figure out how to...
Read more >
Can you programmatically remove DAGs from the Airflow UI?
Delete the DAG from the Airflow UI (there's a red “X” at the right of the “Links” menu in the main DAGs Dashboard...
Read more >
Airflow REST API
Delete a DAG. Deletes all metadata related to the DAG, including finished DAG Runs and Tasks. Logs are not deleted. This action cannot...
Read more >
Using Airflow UI Access Control | Cloud Composer
Google groups cannot be preregistered. Remove users. Deleting a user from Airflow does not revoke access for that user, because they are automatically...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found