davidnzhang commented on code in PR #69171:
URL: https://github.com/apache/airflow/pull/69171#discussion_r3506035004


##########
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:
   We do have all the information available in the main loop. However, putting 
the additional Dag node discovery in the existing traversal (i.e. by stopping 
at each Dag and also looking at its `dep.source` and `dep.target`) means that a 
`dag:` node can then be added to the `nodes_dict` before the outer-most loop 
reaches that Dag. This means we will also need to remove the `if dag_node_id 
not in nodes_dict:` guard or end up skipping over that Dag's own dependencies, 
and I'm not sure if this structural change is worth it.
   
   The standalone patching loop felt a little clearer in intent, is cheap, and 
avoids restructuring the core 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]

Reply via email to