# Buggy code
def _create_dag_runs(self, dag_models: Iterable[DagModel], session: Session) -> None:
    """
    Unconditionally create a DAG run for the given DAG, and update the dag_model's fields to control
    if/when the next DAGRun should be created
    """
    for dag_model in dag_models:
        dag = self.dagbag.get_dag(dag_model.dag_id, session=session)
        dag_hash = self.dagbag.dags_hash.get(dag.dag_id)
        dag.create_dagrun(
            run_type=DagRunType.SCHEDULED,
            execution_date=dag_model.next_dagrun,
            start_date=timezone.utcnow(),
            state=State.RUNNING,
            external_trigger=False,
            session=session,
            dag_hash=dag_hash,
            creating_job_id=self.id,
        )

    self._update_dag_next_dagruns(dag_models, session)


# Traceback (airflow.exceptions.SerializedDagNotFound)
[2021-01-06 10:09:38,742] {scheduler_job.py:1293} ERROR - Exception when executing SchedulerJob._run_scheduler_loop
Traceback (most recent call last):
File "/global/packages/python/lib/python3.7/site-packages/airflow/jobs/scheduler_job.py", line 1275, in _execute
self._run_scheduler_loop()
File "/global/packages/python/lib/python3.7/site-packages/airflow/jobs/scheduler_job.py", line 1377, in _run_scheduler_loop
num_queued_tis = self._do_scheduling(session)
File "/global/packages/python/lib/python3.7/site-packages/airflow/jobs/scheduler_job.py", line 1474, in _do_scheduling
self._create_dag_runs(query.all(), session)
File "/global/packages/python/lib/python3.7/site-packages/airflow/jobs/scheduler_job.py", line 1557, in _create_dag_runs
dag = self.dagbag.get_dag(dag_model.dag_id, session=session)
File "/global/packages/python/lib/python3.7/site-packages/airflow/utils/session.py", line 62, in wrapper
return func(*args, **kwargs)
File "/global/packages/python/lib/python3.7/site-packages/airflow/models/dagbag.py", line 171, in get_dag
self._add_dag_from_db(dag_id=dag_id, session=session)
File "/global/packages/python/lib/python3.7/site-packages/airflow/models/dagbag.py", line 227, in _add_dag_from_db
raise SerializedDagNotFound(f"DAG '{dag_id}' not found in serialized_dag table")
airflow.exceptions.SerializedDagNotFound: DAG 'dynamic_dag_1' not found in serialized_dag table

# Fixed code
def _create_dag_runs(self, dag_models: Iterable[DagModel], session: Session) -> None:
    """
    Unconditionally create a DAG run for the given DAG, and update the dag_model's fields to control
    if/when the next DAGRun should be created
    """
    for dag_model in dag_models:
        try:
            dag = self.dagbag.get_dag(dag_model.dag_id, session=session)
        except SerializedDagNotFound:
            self.log.exception(
                "DAG '%s' not found in serialized_dag table", dag_model.dag_id
            )
            continue

        dag_hash = self.dagbag.dags_hash.get(dag.dag_id)
        dag.create_dagrun(
            run_type=DagRunType.SCHEDULED,
            execution_date=dag_model.next_dagrun,
            start_date=timezone.utcnow(),
            state=State.RUNNING,
            external_trigger=False,
            session=session,
            dag_hash=dag_hash,
            creating_job_id=self.id,
        )

    self._update_dag_next_dagruns(dag_models, session)