dstandish commented on code in PR #32538:
URL: https://github.com/apache/airflow/pull/32538#discussion_r1260562506
##########
airflow/operators/python.py:
##########
@@ -250,25 +251,35 @@ def execute(self, context: Context) -> Any:
if condition:
self.log.info("Proceeding with downstream tasks...")
return condition
-
- downstream_tasks = context["task"].get_flat_relatives(upstream=False)
+ downstream_tasks = [
+ x for x in context["task"].get_flat_relatives(upstream=False) if
not x.is_teardown
+ ]
self.log.debug("Downstream task IDs %s", downstream_tasks)
if downstream_tasks:
dag_run = context["dag_run"]
execution_date = dag_run.execution_date
-
+ if TYPE_CHECKING:
+ assert isinstance(execution_date, DateTime)
if self.ignore_downstream_trigger_rules is True:
self.log.info("Skipping all downstream tasks...")
- self.skip(dag_run, execution_date, downstream_tasks,
map_index=context["ti"].map_index)
+ self.skip(
+ dag_run=dag_run,
+ execution_date=execution_date,
+ tasks=downstream_tasks,
+ map_index=context["ti"].map_index,
+ )
else:
self.log.info("Skipping downstream tasks while respecting
trigger rules...")
# Explicitly setting the state of the direct, downstream
task(s) to "skipped" and letting the
# Scheduler handle the remaining downstream task(s)
appropriately.
+ to_skip = [
+ x for x in
context["task"].get_direct_relatives(upstream=False) if not x.is_teardown
+ ]
Review Comment:
a different way to optimize would to not create the `downstream_tasks` list
at all in the `ignore_downstream_trigger_rules is False` case. then we could
just pass to skip `x for x in
context["task"].get_direct_relatives(upstream=False) if not x.is_teardown` as a
generator since `skip` method can handle that -- i.e. there's not really a need
for selectively calling skip.
but stepping back, i'm not adding any new call to either get_flat_relatives
or get_direct_relatives -- both calls were there and i don't increase their
likelihood of calling or frequency. i just happened to move to a variable cus
it was handy to debug something.
##########
airflow/operators/python.py:
##########
@@ -250,25 +251,35 @@ def execute(self, context: Context) -> Any:
if condition:
self.log.info("Proceeding with downstream tasks...")
return condition
-
- downstream_tasks = context["task"].get_flat_relatives(upstream=False)
+ downstream_tasks = [
+ x for x in context["task"].get_flat_relatives(upstream=False) if
not x.is_teardown
+ ]
self.log.debug("Downstream task IDs %s", downstream_tasks)
if downstream_tasks:
dag_run = context["dag_run"]
execution_date = dag_run.execution_date
-
+ if TYPE_CHECKING:
+ assert isinstance(execution_date, DateTime)
if self.ignore_downstream_trigger_rules is True:
self.log.info("Skipping all downstream tasks...")
- self.skip(dag_run, execution_date, downstream_tasks,
map_index=context["ti"].map_index)
+ self.skip(
+ dag_run=dag_run,
+ execution_date=execution_date,
+ tasks=downstream_tasks,
+ map_index=context["ti"].map_index,
+ )
else:
self.log.info("Skipping downstream tasks while respecting
trigger rules...")
# Explicitly setting the state of the direct, downstream
task(s) to "skipped" and letting the
# Scheduler handle the remaining downstream task(s)
appropriately.
+ to_skip = [
+ x for x in
context["task"].get_direct_relatives(upstream=False) if not x.is_teardown
+ ]
Review Comment:
a different way to optimize would to not create the `downstream_tasks` list
at all in the `ignore_downstream_trigger_rules is False` case. then we could
just pass to skip `x for x in
context["task"].get_direct_relatives(upstream=False) if not x.is_teardown` as a
generator since `skip` method can handle that -- i.e. there's not really a need
for selectively calling skip.
but stepping back, just to be clear, i'm not adding any new call to either
get_flat_relatives or get_direct_relatives -- both calls were there and i don't
increase their likelihood of calling or frequency. i just happened to move to
a variable cus it was handy to debug something.
--
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]