Skip to content

refactor(web): dep-inject payloads with @model_validate - #41501

Merged
asukaminato0721 merged 2 commits into
langgenius:mainfrom
ShousenZHANG:refactor/dep-inject-web-payloads
Aug 31, 2026
Merged

refactor(web): dep-inject payloads with @model_validate#41501
asukaminato0721 merged 2 commits into
langgenius:mainfrom
ShousenZHANG:refactor/dep-inject-web-payloads

Conversation

@ShousenZHANG

@ShousenZHANG ShousenZHANG commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary

part of #36659

Moves the three plain inline Payload.model_validate(web_ns.payload or {}) calls in web/ onto the @model_validate decorator, mirroring the merged service_api conversions (#41374, #41490, #41491). Claimed in this comment; the sibling console/workspace/account.py slice is #41500.

  • audio.pyTextApi.post, where the parse also moves out of the handler's try; the except ValueError arm re-raised unchanged, so a malformed body reached the global handler either way
  • conversation.pyConversationRenameApi.post
  • remote_files.pyRemoteFileUploadApi.post

Deliberately left alone

web/workflow.py, which #40277 is reworking, and web/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_api conversions:

  • TextApi.post: the parse used to sit inside the handler's try, and pydantic's ValidationError is a
    ValueError, so it hit except ValueError as e: raise e and escaped unhandled. An invalid body returned
    500; it now returns 422.
  • ConversationRenameApi.post: validation now runs before the AppMode guard, so a request that is both a
    non-chat app and malformed reports the malformed body (422) instead of NotChatAppError. A valid body
    against a non-chat app still raises NotChatAppError.

How did you test it?

  • pytest tests/unit_tests/controllers/web/243 passed, identical count to main
  • ruff check / ruff format --check — clean; pyrefly check — 0 diagnostics
  • 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, in the container integration test as well as the unit tests — the decorator path itself is exercised by them

This PR was fully generated with an AI assistant. I have reviewed the changes and run the relevant tests.

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.
Copilot AI lite review requested due to automatic review settings August 30, 2026 23:03
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Aug 30, 2026

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@dosubot dosubot Bot added the refactor label Aug 30, 2026
@github-actions

github-actions Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 61.53% 61.53% -0.00%
Strict coverage 61.13% 61.13% -0.00%
Typed symbols 42,641 42,636 -5
Untyped symbols 26,836 26,836 0
Modules 3278 3278 0

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
asukaminato0721 added this pull request to the merge queue Aug 31, 2026
Merged via the queue into langgenius:main with commit 8894b09 Aug 31, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants