Emit warning when Response.background discards injected BackgroundTasks by mango766 · Pull Request #15112 · fastapi/fastapi

@claude

…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: fastapi#11215

Co-Authored-By: Claude (claude-opus-4-6) <noreply@anthropic.com>