Skip to content

fix: stop logging a failed task's error twice - #44

Merged
lesnik512 merged 1 commit into
mainfrom
fix/no-duplicate-teardown-log
Oct 17, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
fix/no-duplicate-teardown-log

Conversation

@lesnik512

Copy link
Copy Markdown
Member

When a task that uses FromDI raised, its traceback was logged twice. The first copy is taskiq's "Exception found while executing function." The second is a teardown warning, "Exception found on dependency teardown", which taskiq-dependencies logs when the exception it throws into a generator dependency with athrow comes back out. build_di_container let it through, so every failed task reported its error a second time, as if teardown had failed.

build_di_container now catches Exception at the yield and returns. The async with still closes the per-task container, and taskiq has already recorded the failure in the task result before it calls athrow. An error raised while closing the container, such as a FinalizerError, happens outside the try, so it is still logged as a teardown error. BaseExceptions such as CancelledError are not caught.

This makes our dependency differ from a plain taskiq generator dependency, which logs the same duplicate. In exchange, a teardown warning from our dependency now always means a real teardown problem.

The new test captures the taskiq.dependencies.ctx log for a failing task and fails on main with that warning. The existing test_per_task_child_closed_on_task_error still checks that the container closes on the error path.

@lesnik512
lesnik512 merged commit aa8bb34 into main Oct 17, 2026
12 checks passed
@lesnik512
lesnik512 deleted the fix/no-duplicate-teardown-log branch October 17, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant