Skip to content

refactor(inner_api): dep-inject workspace payloads with @model_validate - #41540

Open
ShousenZHANG wants to merge 3 commits into
langgenius:mainfrom
ShousenZHANG:refactor/dep-inject-inner-api-workspace
Open

refactor(inner_api): dep-inject workspace payloads with @model_validate#41540
ShousenZHANG wants to merge 3 commits into
langgenius:mainfrom
ShousenZHANG:refactor/dep-inject-inner-api-workspace

Conversation

@ShousenZHANG

@ShousenZHANG ShousenZHANG commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

part of #36659

Moves the three inline parses in inner_api/workspace/workspace.py onto the @model_validate decorator — EnterpriseWorkspace.post, EnterpriseWorkspaceNoOwnerEmail.post and EnterpriseWorkspaceMember.post. Same change as #41374, #41490, #41491, #41500, #41501 and #41539.

Nothing else in inner_api this round: agent/{llm,tools,files}.py and knowledge/retrieval.py raise custom *HttpError(400) from a local except ValidationError, and app/dsl.py:110 returns its own {"code": "invalid_workflow_id"}, 400 — converting those would change documented error contracts rather than just move the parse.

How did you test it?

  • pytest tests/unit_tests/controllers/inner_api/155 passed, against 152 on main; the three extra are the parametrized decorator test added here
  • ruff check / ruff format --check — clean; pyrefly check — 0 diagnostics
  • The three handler test classes patched inner_api_ns to supply the payload; they now put it in the request context and pass the validated model where the decorator injects it. Eight call sites, all in test_workspace.py, verified by handler identity
  • Added a bound-method test for the decorators themselves, parametrized over all three handlers and sent as POST so the decorator reads the JSON body these endpoints actually use. Every other test in the file unwraps the view and builds the model by hand, so without it the decorators would ship unexercised. Verified by mutation: dropping any one of the three fails exactly one case
  • Runtime signature check on all three wrapped handlers

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

Moves the three inline parses in inner_api/workspace/workspace.py onto the
@model_validate decorator: EnterpriseWorkspace.post,
EnterpriseWorkspaceNoOwnerEmail.post and EnterpriseWorkspaceMember.post.

The handler tests patched inner_api_ns to feed the payload; they now put it in
the request context and pass the validated model where the decorator injects it.

Also adds one bound-method test for the decorator, since every other test in the
file unwraps the view and builds the model itself — without it the decorators
here would ship unexercised.
Copilot AI lite review requested due to automatic review settings August 31, 2026 13:20

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.

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 61.77% 61.78% +0.01%
Strict coverage 61.37% 61.38% +0.01%
Typed symbols 42,986 42,994 +8
Untyped symbols 26,777 26,776 -1
Modules 3290 3290 0

…orators

The decorator test passed json= without a method, and test_request_context
defaults to GET, so the decorator took its request.args branch and the JSON body
these three POST handlers actually use was never read — the test passed with a
valid body too. It now sends method="POST" and is parametrized over all three
handlers; each is individually detected when its decorator is removed.

Also drops the blank lines the parse statements left behind.
CI's Python Style job runs pyrefly over tests/ with its own config; the new
parametrized test needed a return annotation and a type for api_cls.
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-08-31 15:59:08.369260738 +0000
+++ /tmp/pyrefly_pr.txt	2026-08-31 15:59:00.597216108 +0000
@@ -3614,6 +3614,8 @@
    --> tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.py:388:35
 ERROR Missing argument `payload` in function `protected_view` [missing-argument]
    --> tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.py:394:36
+ERROR Object of class `Resource` has no attribute `post` [missing-attribute]
+   --> tests/unit_tests/controllers/inner_api/workspace/test_workspace.py:364:17
 ERROR Object of class `FromClause` has no attribute `create` [missing-attribute]
   --> tests/unit_tests/controllers/mcp/test_mcp.py:38:13
 ERROR `SimpleNamespace` is not assignable to attribute `mcp_ns` with type `Namespace` [bad-assignment]

@asukaminato0721
asukaminato0721 added this pull request to the merge queue Sep 1, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Sep 1, 2026
@ShousenZHANG

Copy link
Copy Markdown
Contributor Author

@asukaminato0721 this one has been approved and green since Aug 31 — I think it just got skipped when #41571 and #41575 went through this morning. Still CLEAN, nothing needed from my side.

@asukaminato0721
asukaminato0721 added this pull request to the merge queue Sep 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 2, 2026
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.

3 participants