Skip to content

Instantly share code, notes, and snippets.

@gfranxman
Created July 12, 2023 13:40
Show Gist options
  • Save gfranxman/99fccc82ef224114b37653343126ce66 to your computer and use it in GitHub Desktop.
Save gfranxman/99fccc82ef224114b37653343126ce66 to your computer and use it in GitHub Desktop.
Airflow: Fix for DAG not found in serialized_dag table
While rapidly starting and stoping and changing dags during development, you may run into errors look like this for one or more of the dags:
dag_talk_examples-airflow-scheduler-1 | [2023-07-11 21:07:54,767] {scheduler_job.py:1063} ERROR - DAG 'zimmerman-garcia-and-henry-incremental' not found in serialized_dag table
dag_talk_examples-airflow-scheduler-1 | [2023-07-11 21:07:55,800] {scheduler_job.py:1063} ERROR - DAG 'zimmerman-garcia-and-henry-full' not found in serialized_dag table
dag_talk_examples-airflow-scheduler-1 | [2023-07-11 21:07:55,802] {scheduler_job.py:1063} ERROR - DAG 'zimmerman-garcia-and-henry-incremental' not found in serialized_dag table
dag_talk_examples-airflow-scheduler-1 | [2023-07-11 21:07:56,577] {scheduler_job.py:1063} ERROR - DAG 'zimmerman-garcia-and-henry-incremental' not found in serialized_dag table
dag_talk_examples-airflow-scheduler-1 | [2023-07-11 21:07:56,579] {scheduler_job.py:1063} ERROR - DAG 'zimmerman-garcia-and-henry-full' not found in serialized_dag table
This will fix it.
Pulled from this discussion: https://github.com/apache/airflow/issues/18843
# at some point while starting and stopping the cluster, the dags were not serialized properly.
#
# symptoms:
# - the dags are not visible in the UI
# - the dags are not running
# - the dags are not in the airflow db
# - the dags are in the dags folder
# - "ERROR - DAG '{dag name}' not found in serialized_dag table" error log entries
#
# This script will fix that.
#
from airflow.models import DagBag
from airflow.models.serialized_dag import SerializedDagModel
dag_bag = DagBag()
# Re-serialize any DAGs missing from the database.
for dag_id in dag_bag.dag_ids:
if not SerializedDagModel.get(dag_id):
dag = dag_bag.get_dag(dag_id)
SerializedDagModel.write_dag(dag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment