Repository navigation
Fix teardown TaskFlow tasks failing on reuse and with expand_kwargs - #74782
Open
surawut-jirasaktavee wants to merge 1 commit into
Open
surawut-jirasaktavee wants to merge 1 commit into
surawut-jirasaktavee wants to merge 1 commit into
Conversation
A @teardown function could be used only once. The first call stored the teardown trigger rule in the decorator's own kwargs, so a later call, .override() or .expand() read it as a user-supplied trigger rule and raised ValueError. The same shared state dropped an on_failure_fail_dagrun override after the first task was created. Teardowns mapped with .expand_kwargs() never got the teardown trigger rule and fell back to all_success. When an upstream task failed, the teardown was skipped and the resources it should have cleaned up were left behind.
surawut-jirasaktavee
requested review from
amoghrajesh and
ashb
as code owners
October 15, 2026 07:32
This branch has not been deployed
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
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.
A
@teardownTaskFlow task cannot be used twice in a Dag, and mapping one withexpand_kwargs()gives it the wrong trigger rule.Cause.
__call__andexpand()wrotetrigger_ruleinto the decorator's ownkwargs. The next call, and any.override()copy, saw that stored value as userinput and failed the check meant for users.
__call__also poppedon_failure_fail_dagrunfrom the samekwargs, so a value set through.override(on_failure_fail_dagrun=True)applied only to the first call.expand_kwargs()had no teardown handling at all. A teardown mapped with it gotall_successinstead ofall_done_setup_success, so it was skipped when anupstream task failed.
Fix. Both paths now work on a copy of the decorator's
kwargs. The teardowncheck and trigger rule are applied in one helper, called from
__call__and from_expand(), which serves bothexpand()andexpand_kwargs(). The error messageis unchanged.
Tests. I added five tests to
task-sdk/tests/task_sdk/definitions/decorators/test_setup_teardown.py.All five fail without the fix.
__call__orexpand(), with the second use through.override(task_id=...).on_failure_fail_dagrunset through.override()is kept on a second call.expand_kwargs()setsall_done_setup_success.expand_kwargs()rejects a user-suppliedtrigger_ruleon a teardown, asexpand()does.Checks run locally:
task-sdk/tests/task_sdk/definitions/decorators/andtask-sdk/tests/task_sdk/bases/test_decorator.py: 137 passed.breeze testing task-sdk-tests, the core tests with and without the database, the provider tests with the database, andbreeze build-docsall pass.providers/standard/tests/unit/standard/decorators/pass.prekpasses for both the pre-commit and the manual stages.closes: #74756
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 5.5) following the guidelines