Dev-iL commented on code in PR #58062:
URL: https://github.com/apache/airflow/pull/58062#discussion_r2531528041
##########
airflow-core/src/airflow/models/serialized_dag.py:
##########
@@ -605,6 +605,17 @@ def get(cls, dag_id: str, session: Session = NEW_SESSION)
-> SerializedDagModel
"""
return session.scalar(cls.latest_item_select_object(dag_id))
+ @classmethod
+ def _process_dag_dependencies_query(
+ cls, query, load_json: Callable[[bytes | str], list] | None
+ ) -> Iterator[tuple[str, list]]:
+ """Process query results for DAG dependencies, yielding (dag_id,
dependencies) tuples."""
+ for dag_id, deps_data in query:
+ if load_json is not None:
+ yield (dag_id, load_json(deps_data))
+ else:
+ yield (str(dag_id), deps_data if deps_data else [])
Review Comment:
Since `load_json` doesn't change in the loop, we don't have to check it in
each iteration. We can switch the `if` and the `for`:
```python
deps: list
if load_json is None:
for dag_id, deps_data in query:
deps = deps_data or []
yield (str(dag_id), deps)
else:
for dag_id, deps_data in query:
deps = load_json(deps_data)
yield (str(dag_id), deps)
```
Or one of the below
```python
if load_json is None:
for dag_id, deps_data in query:
yield (str(dag_id), deps_data or [])
else:
for dag_id, deps_data in query:
yield (str(dag_id), load_json(deps_data))
```
```python
if load_json is None:
yield from ((str(dag_id), deps_data or []) for dag_id, deps_data in
query)
else:
yield from ((str(dag_id), load_json(deps_data)) for dag_id, deps_data in
query)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]