Commit Graph

2 Commits

Author SHA1 Message Date
pre-commit-ci-lite[bot] cb0c5f89af
🎨 Auto format 2026-03-14 06:13:14 +00:00
easonysliu 2ea91122c9 Emit UserWarning when Response.background silently discards injected BackgroundTasks
When an endpoint injects BackgroundTasks via dependency injection AND
returns a Response that already has its own `background` attribute set,
the injected tasks are silently dropped. This is a confusing footgun
that causes tasks to disappear without any indication.

This change adds a UserWarning in that scenario so the silent data loss
becomes visible. The warning message explains how to resolve the
conflict (either use the injected BackgroundTasks exclusively, or stop
injecting BackgroundTasks when using Response.background directly).

Ref: https://github.com/fastapi/fastapi/issues/11215

Co-Authored-By: Claude (claude-opus-4-6) <noreply@anthropic.com>
2026-03-14 14:08:25 +08:00