What is the best practice for removing dags from your UI that were dynamically generated?
For instance, if I had code that generates dags dynamically from a database table and one of the dags were removed, it still exists in the UI (because the dag still exists in the database even though it’s no longer in the dagbag).
How do I remove these dags cleanly and automatically? Is the only way to manually delete it in the database?
You CAN leverage the Airflow CLI command airflow delete_dag, which you can run on Astronomer Enterprise by wrapping the Airflow CLI command around a kubectl exec command on your Scheduler or Webserver Pod
E.g. kubectl exec -it {scheduler-container] bash -c ..."
There is currently no add DAG or delete DAG endpoint exposed via the current API, but a restructured API is a milestone our team + the Airflow community is very much working towards that should help users programmatically delete dynamically generated DAGs in the future
My question is related to this topic. I generate DAGs automatically using a python script which selects configurations from BigQuery. Works like a charm, but when I disable one config for a dag, i can see in the webserver log that that DAG is no longer in the dagbag. But it doesn’t get deleted from the database, I guess, because it remains in the UI. Does it disappear after some time or do I also need to add some dag-delete code in my script? Hope to hear from you.