pierrejeambrun commented on code in PR #26658:
URL: https://github.com/apache/airflow/pull/26658#discussion_r1010331735


##########
airflow/utils/task_group.py:
##########
@@ -454,6 +455,26 @@ def topological_sort(self, _include_subdag_tasks: bool = 
False):
 
         return graph_sorted
 
+    def get_task_dict(self) -> dict[str, AbstractOperator]:
+        """Returns a flat dictionary of task_id: AbstractOperator"""
+        task_map: dict[str, AbstractOperator] = {}
+        groups_to_visit = [self]
+
+        while groups_to_visit:
+            visiting = groups_to_visit.pop(0)
+
+            for child in visiting.children.values():
+                if isinstance(child, AbstractOperator):
+                    task_map[child.task_id] = child
+                elif isinstance(child, TaskGroup):
+                    groups_to_visit.append(child)
+                else:
+                    raise ValueError(
+                        f"Encountered a DAGNode that is not a TaskGroup or an 
AbstractOperator: {type(child)}"
+                    )
+
+        return task_map

Review Comment:
   True, for this specific use case, this is much better. Thanks !
   
   Done 



-- 
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