-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Fix deferred task resumption in dag.test()
#51182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When using `dag.test()` with deferred tasks, tasks that complete their trigger execution were incorrectly being set to `SUCCESS` state instead of `SCHEDULED` state. This prevented task resumption!
Dag used to test:
```python
from datetime import datetime, timedelta, timezone
from typing import Any
import pendulum
from airflow.providers.standard.triggers.temporal import DateTimeTrigger
from airflow.sdk import Context, task, BaseOperator, DAG
class DummyOperator(BaseOperator):
def execute(self, context: Context):
self.defer(
trigger=DateTimeTrigger(
moment=datetime.now(timezone.utc) + timedelta(seconds=2),
),
method_name="execute_complet",
)
def execute_complet(self, context: Context, event: Any = None):
assert event is not None
return "test"
@task
def dummy_task(param):
print("DEBUG")
assert param == "test", "Parameter should be 'test'"
with DAG(
dag_id="example_debug",
start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
) as dag:
task1 = DummyOperator(task_id="task1")
task2 = dummy_task(task1.output)
task1 >> task2
if __name__ == "__main__":
dag.test()
```
amoghrajesh
reviewed
May 29, 2025
amoghrajesh
approved these changes
May 29, 2025
github-actions bot
pushed a commit
that referenced
this pull request
May 29, 2025
When using `dag.test()` with deferred tasks, tasks that complete their trigger execution were incorrectly being set to `SUCCESS` state instead of `SCHEDULED` state. This prevented task resumption!
Dag used to test:
```python
from datetime import datetime, timedelta, timezone
from typing import Any
import pendulum
from airflow.providers.standard.triggers.temporal import DateTimeTrigger
from airflow.sdk import Context, task, BaseOperator, DAG
class DummyOperator(BaseOperator):
def execute(self, context: Context):
self.defer(
trigger=DateTimeTrigger(
moment=datetime.now(timezone.utc) + timedelta(seconds=2),
),
method_name="execute_complet",
)
def execute_complet(self, context: Context, event: Any = None):
assert event is not None
return "test"
@task
def dummy_task(param):
print("DEBUG")
assert param == "test", "Parameter should be 'test'"
with DAG(
dag_id="example_debug",
start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
) as dag:
task1 = DummyOperator(task_id="task1")
task2 = dummy_task(task1.output)
task1 >> task2
if __name__ == "__main__":
dag.test()
```
(cherry picked from commit 1b83f71)
Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com>
github-actions bot
pushed a commit
to aws-mwaa/upstream-to-airflow
that referenced
this pull request
May 29, 2025
) When using `dag.test()` with deferred tasks, tasks that complete their trigger execution were incorrectly being set to `SUCCESS` state instead of `SCHEDULED` state. This prevented task resumption! Dag used to test: ```python from datetime import datetime, timedelta, timezone from typing import Any import pendulum from airflow.providers.standard.triggers.temporal import DateTimeTrigger from airflow.sdk import Context, task, BaseOperator, DAG class DummyOperator(BaseOperator): def execute(self, context: Context): self.defer( trigger=DateTimeTrigger( moment=datetime.now(timezone.utc) + timedelta(seconds=2), ), method_name="execute_complet", ) def execute_complet(self, context: Context, event: Any = None): assert event is not None return "test" @task def dummy_task(param): print("DEBUG") assert param == "test", "Parameter should be 'test'" with DAG( dag_id="example_debug", start_date=pendulum.datetime(2021, 1, 1, tz="UTC"), ) as dag: task1 = DummyOperator(task_id="task1") task2 = dummy_task(task1.output) task1 >> task2 if __name__ == "__main__": dag.test() ``` (cherry picked from commit 1b83f71) Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com>
kaxil
added a commit
that referenced
this pull request
May 29, 2025
…51199) When using `dag.test()` with deferred tasks, tasks that complete their trigger execution were incorrectly being set to `SUCCESS` state instead of `SCHEDULED` state. This prevented task resumption! Dag used to test: ```python from datetime import datetime, timedelta, timezone from typing import Any import pendulum from airflow.providers.standard.triggers.temporal import DateTimeTrigger from airflow.sdk import Context, task, BaseOperator, DAG class DummyOperator(BaseOperator): def execute(self, context: Context): self.defer( trigger=DateTimeTrigger( moment=datetime.now(timezone.utc) + timedelta(seconds=2), ), method_name="execute_complet", ) def execute_complet(self, context: Context, event: Any = None): assert event is not None return "test" @task def dummy_task(param): print("DEBUG") assert param == "test", "Parameter should be 'test'" with DAG( dag_id="example_debug", start_date=pendulum.datetime(2021, 1, 1, tz="UTC"), ) as dag: task1 = DummyOperator(task_id="task1") task2 = dummy_task(task1.output) task1 >> task2 if __name__ == "__main__": dag.test() ``` (cherry picked from commit 1b83f71) Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com>
Contributor
|
Thank you! |
kaxil
added a commit
that referenced
this pull request
Jun 3, 2025
…51199) When using `dag.test()` with deferred tasks, tasks that complete their trigger execution were incorrectly being set to `SUCCESS` state instead of `SCHEDULED` state. This prevented task resumption! Dag used to test: ```python from datetime import datetime, timedelta, timezone from typing import Any import pendulum from airflow.providers.standard.triggers.temporal import DateTimeTrigger from airflow.sdk import Context, task, BaseOperator, DAG class DummyOperator(BaseOperator): def execute(self, context: Context): self.defer( trigger=DateTimeTrigger( moment=datetime.now(timezone.utc) + timedelta(seconds=2), ), method_name="execute_complet", ) def execute_complet(self, context: Context, event: Any = None): assert event is not None return "test" @task def dummy_task(param): print("DEBUG") assert param == "test", "Parameter should be 'test'" with DAG( dag_id="example_debug", start_date=pendulum.datetime(2021, 1, 1, tz="UTC"), ) as dag: task1 = DummyOperator(task_id="task1") task2 = dummy_task(task1.output) task1 >> task2 if __name__ == "__main__": dag.test() ``` (cherry picked from commit 1b83f71) Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com>
sanederchik
pushed a commit
to sanederchik/airflow
that referenced
this pull request
Jun 7, 2025
When using `dag.test()` with deferred tasks, tasks that complete their trigger execution were incorrectly being set to `SUCCESS` state instead of `SCHEDULED` state. This prevented task resumption!
Dag used to test:
```python
from datetime import datetime, timedelta, timezone
from typing import Any
import pendulum
from airflow.providers.standard.triggers.temporal import DateTimeTrigger
from airflow.sdk import Context, task, BaseOperator, DAG
class DummyOperator(BaseOperator):
def execute(self, context: Context):
self.defer(
trigger=DateTimeTrigger(
moment=datetime.now(timezone.utc) + timedelta(seconds=2),
),
method_name="execute_complet",
)
def execute_complet(self, context: Context, event: Any = None):
assert event is not None
return "test"
@task
def dummy_task(param):
print("DEBUG")
assert param == "test", "Parameter should be 'test'"
with DAG(
dag_id="example_debug",
start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
) as dag:
task1 = DummyOperator(task_id="task1")
task2 = dummy_task(task1.output)
task1 >> task2
if __name__ == "__main__":
dag.test()
```
jose-lehmkuhl
pushed a commit
to jose-lehmkuhl/airflow
that referenced
this pull request
Jul 11, 2025
When using `dag.test()` with deferred tasks, tasks that complete their trigger execution were incorrectly being set to `SUCCESS` state instead of `SCHEDULED` state. This prevented task resumption!
Dag used to test:
```python
from datetime import datetime, timedelta, timezone
from typing import Any
import pendulum
from airflow.providers.standard.triggers.temporal import DateTimeTrigger
from airflow.sdk import Context, task, BaseOperator, DAG
class DummyOperator(BaseOperator):
def execute(self, context: Context):
self.defer(
trigger=DateTimeTrigger(
moment=datetime.now(timezone.utc) + timedelta(seconds=2),
),
method_name="execute_complet",
)
def execute_complet(self, context: Context, event: Any = None):
assert event is not None
return "test"
@task
def dummy_task(param):
print("DEBUG")
assert param == "test", "Parameter should be 'test'"
with DAG(
dag_id="example_debug",
start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
) as dag:
task1 = DummyOperator(task_id="task1")
task2 = dummy_task(task1.output)
task1 >> task2
if __name__ == "__main__":
dag.test()
```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #50300 (comment)
When using
dag.test()with deferred tasks, tasks that complete their trigger execution were incorrectly being set toSUCCESSstate instead ofSCHEDULEDstate. This prevented task resumption!Dag used to test:
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.