Skip to content

fix fastapi middleware swallowing user routes bodies#3805

Merged
T4rk1n merged 3 commits into
devfrom
fix/fastapi-middleware
Jun 3, 2026
Merged

fix fastapi middleware swallowing user routes bodies#3805
T4rk1n merged 3 commits into
devfrom
fix/fastapi-middleware

Conversation

@T4rk1n
Copy link
Copy Markdown
Contributor

@T4rk1n T4rk1n commented Jun 2, 2026

Fixes #3801

Comment thread dash/backends/_fastapi.py
prefix = self.dash_app.config.routes_pathname_prefix
if "_dash-" not in path and path != prefix and path != prefix.rstrip("/"):
await self.app(scope, receive, send)
return
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning here skips _run_before_hooks and _run_after_hooks. Is that intentional? You could move the check inside the try/except block and only call _setup_timing if it's a Dash route.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes intentional, those are only for emulating the flask api for the dash setup, not intended for the user to use.

Comment thread dash/backends/_fastapi.py Outdated
# Non-Dash routes pass through to avoid consuming body stream
path = scope["path"]
prefix = self.dash_app.config.routes_pathname_prefix
if "_dash-" not in path and path != prefix and path != prefix.rstrip("/"):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would match a path like "_dash-my-awesome-path", which would be a false positive. It might be worth making this check a bit more specific. Though it seems like no one would actually do this.

Copy link
Copy Markdown
Contributor Author

@T4rk1n T4rk1n Jun 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea better put the prefix and startwith check. Other it could catch some random route like /my_dash-favorite

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 3, 2026

@T4rk1n T4rk1n merged commit aa35e38 into dev Jun 3, 2026
30 of 31 checks passed
@T4rk1n T4rk1n deleted the fix/fastapi-middleware branch June 3, 2026 22:06
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] dash 4.2.0-Dash 4.3.0rc0 POST deadlock

2 participants