davidnzhang commented on code in PR #69171:
URL: https://github.com/apache/airflow/pull/69171#discussion_r3506135212
##########
airflow-core/src/airflow/api_fastapi/core_api/services/ui/dependencies.py:
##########
@@ -135,6 +135,19 @@ def get_scheduling_dependencies(readable_dag_ids: set[str]
| None = None) -> dic
target = dep.target if ":" in dep.target else
f"dag:{dep.target}"
edge_tuples.add((source, target))
+ # Create missing ``dag:`` nodes which may have been skipped by the loop
above.
+ # A DAG referenced only as a trigger target or a sensor source may have no
+ # scheduling dependencies of its own. Without this loop, these DAGs will
not be
+ # materialised and will result in dangling edges.
+ for source, target in edge_tuples:
+ for endpoint in (source, target):
+ if endpoint.startswith("dag:") and endpoint not in nodes_dict:
+ nodes_dict[endpoint] = {
+ "id": endpoint,
+ "label": endpoint.removeprefix("dag:"),
+ "type": "dag",
+ }
Review Comment:
This is what I think the in-loop change would look like (instead of the full
pass):
```python
...
for dag, dependencies in sorted(dag_dependencies.items()):
if readable_dag_ids is not None and dag not in readable_dag_ids:
continue
dag_node_id = f"dag:{dag}"
# if dag_node_id not in nodes_dict: REMOVED
for dep in dependencies:
...
# Add nodes
nodes_dict[dag_node_id] = {"id": dag_node_id, "label": dag, "type":
"dag"}
# ADDED: discover dag nodes from dep.source and dep.target
for endpoint in (dep.source, dep.target):
if endpoint == dep.dependency_type or ":" in endpoint:
continue
endpoint_dag_node_id = f"dag:{endpoint}"
if endpoint_dag_node_id not in nodes_dict:
nodes_dict[endpoint_dag_node_id] = {
"id": endpoint_dag_node_id,
"label": endpoint,
"type": "dag",
}
if dep.node_id not in nodes_dict:
nodes_dict[dep.node_id] = {
"id": dep.node_id,
"label": dep.label,
"type": dep.dependency_type,
}
# Add edges
...
# for source, target in edge_tuples: REMOVED (post pass loop)
```
--
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]