fix(upload): handle unknown event handlers - #6861
Conversation
Signed-off-by: hariomloharapps <hariomlohar.new@gmail.com>
Greptile SummaryThis PR attempts to return a controlled 400 response when an upload request references an unregistered event handler.
Confidence Score: 4/5This PR is not safe to merge until the registry lookup uses the handler-name string rather than an unhashable list. The changed lookup raises Files Needing Attention: packages/reflex-components-core/src/reflex_components_core/core/_upload.py
|
| Filename | Overview |
|---|---|
| packages/reflex-components-core/src/reflex_components_core/core/_upload.py | Adds unknown-handler validation, but the list passed to dict.get raises TypeError before the validation can run. |
| tests/units/test_app.py | Adds focused coverage for the intended 400 response; the test should expose the malformed registry lookup when run. |
Reviews (1): Last reviewed commit: "fix(upload): handle unknown event handle..." | Re-trigger Greptile
| registered_event_handler = RegistrationContext.get().event_handlers.get([ | ||
| handler_name | ||
| ] | ||
| ]) |
There was a problem hiding this comment.
List key breaks handler lookup
When any upload request supplies the required handler header, passing [handler_name] to the plain dictionary's get method raises TypeError: unhashable type: 'list', causing valid uploads and the intended unknown-handler rejection to fail before the new guard runs.
| registered_event_handler = RegistrationContext.get().event_handlers.get([ | |
| handler_name | |
| ] | |
| ]) | |
| registered_event_handler = RegistrationContext.get().event_handlers.get( | |
| handler_name | |
| ) |
There was a problem hiding this comment.
1 issue found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/reflex-components-core/src/reflex_components_core/core/_upload.py">
<violation number="1" location="packages/reflex-components-core/src/reflex_components_core/core/_upload.py:809">
P1: Upload requests now fail with `TypeError: unhashable type: 'list'` before handler resolution, including registered handlers. Pass `handler_name` directly to `.get()` so unknown handlers reach the intended 400 response.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| registered_event_handler = RegistrationContext.get().event_handlers.get([ | ||
| handler_name | ||
| ] | ||
| ]) |
There was a problem hiding this comment.
P1: Upload requests now fail with TypeError: unhashable type: 'list' before handler resolution, including registered handlers. Pass handler_name directly to .get() so unknown handlers reach the intended 400 response.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/reflex-components-core/src/reflex_components_core/core/_upload.py, line 809:
<comment>Upload requests now fail with `TypeError: unhashable type: 'list'` before handler resolution, including registered handlers. Pass `handler_name` directly to `.get()` so unknown handlers reach the intended 400 response.</comment>
<file context>
@@ -805,9 +806,14 @@ async def upload_file(request: Request):
token, handler_name = _require_upload_headers(request)
- registered_event_handler = RegistrationContext.get().event_handlers[
+ registered_event_handler = RegistrationContext.get().event_handlers.get([
handler_name
- ]
</file context>
| registered_event_handler = RegistrationContext.get().event_handlers.get([ | |
| handler_name | |
| ] | |
| ]) | |
| registered_event_handler = RegistrationContext.get().event_handlers.get( | |
| handler_name | |
| ) |
|
Thanks for the focused fix and regression test. I think there is one blocker before this can merge.
registered_event_handler = RegistrationContext.get().event_handlers.get([ Because [handler_name] is a list, this raises TypeError: cannot use 'list' as a dict key for both unknown handlers and uv run --frozen pytest tests/units/test_app.py::test_upload_file_unknown_handler_returns_400 tests/units/ Result: 4 failed, all from that lookup. This should be: registered_event_handler = RegistrationContext.get().event_handlers.get( Also, since this is a user-facing upload bugfix for #6860, towncrier check currently fails because there is no news |
All Submissions:
Type of change
New Feature Submission:
Not applicable — this is a bug fix.
Changes To Core Features:
Description
Fixes #6860
The upload endpoint previously performed a direct registry lookup for the
Reflex-Event-Handlerheader. If the header referenced an unknown or stale event handler, the lookup raised an unhandledKeyErrorand resulted in a 500 response.This change:
.get().400 Bad Requestfor an unknown upload event handler.Valid registered upload handlers continue to follow the existing behavior.