|
37 | 37 | TaskAlreadyInTaskGroup, |
38 | 38 | ) |
39 | 39 | from airflow.sdk.definitions.node import DAGNode |
| 40 | +from airflow.utils.trigger_rule import TriggerRule |
40 | 41 |
|
41 | 42 | if TYPE_CHECKING: |
42 | 43 | from airflow.models.expandinput import ExpandInput |
@@ -195,10 +196,15 @@ def task_group(self, value: TaskGroup | None): |
195 | 196 |
|
196 | 197 | def __iter__(self): |
197 | 198 | for child in self.children.values(): |
198 | | - if isinstance(child, TaskGroup): |
199 | | - yield from child |
200 | | - else: |
201 | | - yield child |
| 199 | + yield from self._iter_child(child) |
| 200 | + |
| 201 | + @staticmethod |
| 202 | + def _iter_child(child): |
| 203 | + """Iterate over the children of this TaskGroup.""" |
| 204 | + if isinstance(child, TaskGroup): |
| 205 | + yield from child |
| 206 | + else: |
| 207 | + yield child |
202 | 208 |
|
203 | 209 | def add(self, task: DAGNode) -> DAGNode: |
204 | 210 | """ |
@@ -574,6 +580,14 @@ def __init__(self, *, expand_input: ExpandInput, **kwargs: Any) -> None: |
574 | 580 | super().__init__(**kwargs) |
575 | 581 | self._expand_input = expand_input |
576 | 582 |
|
| 583 | + def __iter__(self): |
| 584 | + from airflow.models.abstractoperator import AbstractOperator |
| 585 | + |
| 586 | + for child in self.children.values(): |
| 587 | + if isinstance(child, AbstractOperator) and child.trigger_rule == TriggerRule.ALWAYS: |
| 588 | + raise ValueError("Tasks in a mapped task group cannot have trigger_rule set to 'ALWAYS'") |
| 589 | + yield from self._iter_child(child) |
| 590 | + |
577 | 591 | def iter_mapped_dependencies(self) -> Iterator[DAGNode]: |
578 | 592 | """Upstream dependencies that provide XComs used by this mapped task group.""" |
579 | 593 | from airflow.models.xcom_arg import XComArg |
|
0 commit comments