refactor(web): dep-inject payloads with @model_validate - #41501
Merged
asukaminato0721 merged 2 commits intoAug 31, 2026
Merged
Conversation
Moves the three plain inline `Payload.model_validate(web_ns.payload or {})`
calls in web/ onto the @model_validate decorator, mirroring the service_api
conversion.
- audio.py: TextApi.post, where the parse also moves out of the handler's try
- conversation.py: ConversationRenameApi.post
- remote_files.py: RemoteFileUploadApi.post
Left alone: web/workflow.py (being reworked by langgenius#40277) and web/completion.py,
whose parses go through omit_trace_session_id_from_payload and need a decorator
variant rather than a mechanical move.
The web tests call the bound handlers through the live decorator, so their
payloads move from a web_ns mock into test_request_context(json=...), and the
now-dead web_ns patches are dropped.
Contributor
Pyrefly Type Coverage
|
ConversationRenameApi.post no longer reads web_ns.payload, so the two patches in the container integration test are inert. The tests already pass the body through test_request_context, so behaviour is unchanged.
asukaminato0721
enabled auto-merge
August 31, 2026 00:30
asukaminato0721
approved these changes
Aug 31, 2026
This was referenced Aug 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
part of #36659
Moves the three plain inline
Payload.model_validate(web_ns.payload or {})calls inweb/onto the@model_validatedecorator, mirroring the mergedservice_apiconversions (#41374, #41490, #41491). Claimed in this comment; the siblingconsole/workspace/account.pyslice is #41500.audio.py—TextApi.post, where the parse also moves out of the handler's try; theexcept ValueErrorarm re-raised unchanged, so a malformed body reached the global handler either wayconversation.py—ConversationRenameApi.postremote_files.py—RemoteFileUploadApi.postDeliberately left alone
web/workflow.py, which #40277 is reworking, andweb/completion.py, which #39706 has hunks in. Both of those parses are the same plain shape as the three converted here — I left them for whoever lands after those PRs rather than create a conflict.Behaviour notes
Two observable changes, both the same family as the merged
service_apiconversions:TextApi.post: the parse used to sit inside the handler'stry, and pydantic'sValidationErroris aValueError, so it hitexcept ValueError as e: raise eand escaped unhandled. An invalid body returned500; it now returns 422.
ConversationRenameApi.post: validation now runs before theAppModeguard, so a request that is both anon-chat app and malformed reports the malformed body (422) instead of
NotChatAppError. A valid bodyagainst a non-chat app still raises
NotChatAppError.How did you test it?
pytest tests/unit_tests/controllers/web/— 243 passed, identical count tomainruff check/ruff format --check— clean;pyrefly check— 0 diagnosticsweb_nsmock intotest_request_context(json=...)and the now-deadweb_nspatches are dropped, in the container integration test as well as the unit tests — the decorator path itself is exercised by themThis PR was fully generated with an AI assistant. I have reviewed the changes and run the relevant tests.