Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer/workflows/airflow_db_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def cleanup_function(**context):
dags = session.query(airflow_db_model.dag_id).distinct()
session.commit()

list_dags = [str(list(dag)[0]) for dag in dags] + [None]
list_dags = [str(list(dag)[0]) for dag in dags]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this change correctly removes the redundant None iteration, the list comprehension can be made more efficient and readable. The dags query returns an iterable of tuple-like Row objects. You can access the first element directly using index [0] instead of converting each row to a list first. This avoids creating an unnecessary intermediate list for each DAG.

Suggested change
list_dags = [str(list(dag)[0]) for dag in dags]
list_dags = [str(dag[0]) for dag in dags]

for dag_id in list_dags:
query = build_query(
session=session,
Expand Down