Skip to content

Fix Redirect responses with background tasks - #921

Open
tunglambk wants to merge 1 commit into
AnswerDotAI:mainfrom
tunglambk:fix/redirect-background-task
Open

Fix Redirect responses with background tasks#921
tunglambk wants to merge 1 commit into
AnswerDotAI:mainfrom
tunglambk:fix/redirect-background-task

Conversation

@tunglambk

Copy link
Copy Markdown

Related Issue

Fixes #728

Proposed Changes

Normalize objects implementing __response__ when they are returned inside a
tuple, not only when they are the entire route result. When that produces a
Starlette response, attach any tuple-provided background tasks while preserving
an existing response background task.

Previously, (Redirect("/"), BackgroundTask(...)) skipped the redirect's
__response__ conversion. FastHTML rendered the Redirect object as HTML and
returned 200 instead of 303.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I am aware that this is an nbdev project, and I have edited, cleaned, and synced the source notebooks instead of editing .py or .md files directly.

Additional Information

Validated the regression for standard and HTMX redirects, including task
execution and composition with an existing response background task. The
existing tests/test_toaster.py script passes. The core notebook executes the
new regression successfully, then later stops at the unrelated existing
into() default-title assertion with the latest resolved dependencies.

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.

[BUG] Adding BackgroundTask to Redirect results in 200 response.

1 participant