You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Chais (via GitHub)" <gi...@apache.org> on 2024/11/08 11:08:17 UTC

[D] ShortCircuitOperator not short-circuiting as expected [airflow]

GitHub user Chais created a discussion: ShortCircuitOperator not short-circuiting as expected

Here's my DAG:
```python
import random
from typing import List

import pendulum
from airflow.decorators import dag, task


@dag(
    "test_foo",
    schedule=None,
    start_date=pendulum.now(),
    render_template_as_native_obj=True,
    dag_display_name="Test random things",
)
def test_foo():
    @task.python
    def start() -> List[int]:
        return [i for i in range(10)]

    @task.short_circuit
    def step_one(i: int) -> bool:
        print(f"Hello from task {i}")
        return random.random() >= 0.5

    @task.python
    def step_two(do: bool):
        print(f"{"D" if do else "Not d"}oing stuff")

    step_two.expand(do=step_one.expand(i=start()))


test_foo()
```
This results in 21 tasks total, as expected. My issue, or misunderstanding maybe, is that in `step_one` if the output is `False` the ShortCircuitOperator logs `No downstream tasks; nothing to do`, even though there clearly is one for each task. 
How do I get this to behave as expected?

GitHub link: https://github.com/apache/airflow/discussions/43816

----
This is an automatically sent email for commits@airflow.apache.org.
To unsubscribe, please send an email to: commits-unsubscribe@airflow.apache.org


Re: [D] ShortCircuitOperator not short-circuiting as expected with expanded tasks [airflow]

Posted by "Chais (via GitHub)" <gi...@apache.org>.
GitHub user Chais edited a discussion: ShortCircuitOperator not short-circuiting as expected with expanded tasks

Here's my DAG:
```python
import random
from typing import List

import pendulum
from airflow.decorators import dag, task


@dag(
    "test_foo",
    schedule=None,
    start_date=pendulum.now(),
    render_template_as_native_obj=True,
    dag_display_name="Test random things",
)
def test_foo():
    @task.python
    def start() -> List[int]:
        return [i for i in range(10)]

    @task.short_circuit
    def step_one(i: int) -> bool:
        print(f"Hello from task {i}")
        return random.random() >= 0.5

    @task.python
    def step_two(do: bool):
        print(f"{"D" if do else "Not d"}oing stuff")

    step_two.expand(do=step_one.expand(i=start()))


test_foo()
```
This results in 21 tasks total, as expected. My issue, or misunderstanding maybe, is that in `step_one` if the output is `False` the ShortCircuitOperator logs `No downstream tasks; nothing to do`, even though there clearly is one for each task. 
How do I get this to behave as expected?

GitHub link: https://github.com/apache/airflow/discussions/43816

----
This is an automatically sent email for commits@airflow.apache.org.
To unsubscribe, please send an email to: commits-unsubscribe@airflow.apache.org