Skip to content

fix(upload): handle unknown event handlers - #6861

Merged
FarhanAliRaza merged 6 commits into
reflex-dev:mainfrom
hariomlohardev:fix/6860-upload-unknown-handler
Sep 14, 2026
Merged

FarhanAliRaza merged 6 commits into
reflex-dev:mainfrom
hariomlohardev:fix/6860-upload-unknown-handler

Conversation

@hariomlohardev

@hariomlohardev hariomlohardev commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

All Submissions:

Type of change

  • Bug fix (non-breaking change which fixes an existing issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

New Feature Submission:

Not applicable — this is a bug fix.

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Description

Fixes #6860

The upload endpoint previously performed a direct registry lookup for the Reflex-Event-Handler header. If the header referenced an unknown or stale event handler, the lookup raised an unhandled KeyError and resulted in a 500 response.

This change:

  • Uses a guarded registry lookup with .get().
  • Returns a controlled 400 Bad Request for an unknown upload event handler.
  • Adds a focused unit test covering the unknown-handler case.
  • Ensures the invalid handler is rejected before form parsing or event dispatch.

Valid registered upload handlers continue to follow the existing behavior.

Review in cubic

@hariomlohardev
hariomlohardev requested a review from a team as a code owner August 8, 2026 19:13
@greptile-apps

greptile-apps Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge with no outstanding correctness or repository-rule issues.

Summary

  • Replaces the direct event-handler registry lookup with a guarded lookup.
  • Adds a focused regression test for an unknown handler.
  • Adds the required package news fragment.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

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.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@harsh21234i

harsh21234i commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the focused fix and regression test. I think there is one blocker before this can merge.

packages/reflex-components-core/src/reflex_components_core/core/_upload.py currently does:

registered_event_handler = RegistrationContext.get().event_handlers.get([
handler_name
])

Because [handler_name] is a list, this raises TypeError: cannot use 'list' as a dict key for both unknown handlers and
valid registered upload handlers. I confirmed it by running:

uv run --frozen pytest tests/units/test_app.py::test_upload_file_unknown_handler_returns_400 tests/units/
test_app.py::test_upload_file -q

Result: 4 failed, all from that lookup.

This should be:

registered_event_handler = RegistrationContext.get().event_handlers.get(
handler_name
)

Also, since this is a user-facing upload bugfix for #6860, towncrier check currently fails because there is no news
fragment. Please add a bugfix fragment, likely packages/reflex-components-core/news/6860.bugfix.md or
news/6860.bugfix.md, depending maintainer preference.

@hariomlohardev

Copy link
Copy Markdown
Contributor Author

Thanks for the focused fix and regression test. I think there is one blocker before this can merge.

packages/reflex-components-core/src/reflex_components_core/core/_upload.py currently does:

registered_event_handler = RegistrationContext.get().event_handlers.get([ handler_name ])

Because [handler_name] is a list, this raises TypeError: cannot use 'list' as a dict key for both unknown handlers and valid registered upload handlers. I confirmed it by running:

uv run --frozen pytest tests/units/test_app.py::test_upload_file_unknown_handler_returns_400 tests/units/ test_app.py::test_upload_file -q

Result: 4 failed, all from that lookup.

This should be:

registered_event_handler = RegistrationContext.get().event_handlers.get( handler_name )

Also, since this is a user-facing upload bugfix for #6860, towncrier check currently fails because there is no news fragment. Please add a bugfix fragment, likely packages/reflex-components-core/news/6860.bugfix.md or news/6860.bugfix.md, depending maintainer preference.

Done 😊

@harsh21234i

Copy link
Copy Markdown
Contributor

One maintainer-readiness change is still needed: because this is a user-facing bugfix in reflex-components-core,
please add a package news fragment at:

packages/reflex-components-core/news/6860.bugfix.md

Suggested content:

Return a controlled 400 response when an upload request references an unknown event handler.

I also don’t see unit or integration CI results for the current commit yet. Please confirm the focused test and
relevant checks pass before merge.

@harsh21234i

Copy link
Copy Markdown
Contributor

LGTM!

@hariomlohardev

Copy link
Copy Markdown
Contributor Author

LGTM!

When it will be merged

@reflex-dev reflex-dev deleted a comment from hariomlohardev Aug 24, 2026
@codspeed

codspeed Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 3.17%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 39 untouched benchmarks
⏩ 8 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_var_access[mutable_dict] 47 ms 45.6 ms +3.17%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing hariomlohardev:fix/6860-upload-unknown-handler (edf0bf9) with main (5d9724e)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@FarhanAliRaza
FarhanAliRaza merged commit 3222423 into reflex-dev:main Sep 14, 2026
111 checks passed
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.

Upload endpoint returns 500 for unknown Reflex-Event-Handler header

4 participants