Skip to content

Commit

Permalink
Don't create session in get_dag if not reading dags from database (ap…
Browse files Browse the repository at this point in the history
…ache#38553)

The function DagBag.get_dag has some logic to check if the serialized dag object should be refreshed. By accessing the dags dict directly we avoid that logic, and this is helpful for running a task exclusively with the internal API.  Generally speaking this function "get_dag" is invoked when running the task command on a worker, and in that context we shouldn't need to handle expiration of the serdag.  For the case where we're reading from db, I have left the original method call in place (which keeps the expiration logic in effect for that scenario).

---------

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
  • Loading branch information
2 people authored and idantepper@gmail.com committed Apr 3, 2024
1 parent 16d05cc commit 7092ea1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion airflow/utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,11 @@ def get_dag(subdir: str | None, dag_id: str, from_db: bool = False) -> DAG:

if from_db:
dagbag = DagBag(read_dags_from_db=True)
dag = dagbag.get_dag(dag_id) # get_dag loads from the DB as requested
else:
first_path = process_subdir(subdir)
dagbag = DagBag(first_path)
dag = dagbag.get_dag(dag_id)
dag = dagbag.dags.get(dag_id) # avoids db calls made in get_dag
if not dag:
if from_db:
raise AirflowException(f"Dag {dag_id!r} could not be found in DagBag read from database.")
Expand Down

0 comments on commit 7092ea1

Please sign in to comment.