Skip to content

refactor(controllers/console): dep-inject workflow payloads with @model_validate - #41244

Open
Terminator666666 wants to merge 2 commits into
langgenius:mainfrom
Terminator666666:refactor/workflow-controller-model-validate
Open

refactor(controllers/console): dep-inject workflow payloads with @model_validate#41244
Terminator666666 wants to merge 2 commits into
langgenius:mainfrom
Terminator666666:refactor/workflow-controller-model-validate

Conversation

@Terminator666666

Copy link
Copy Markdown

Summary

Part of #36659 (claimed in the issue comments).

Migrates controllers/console/app/workflow.py to the @model_validate decorator. This was the largest remaining batch of inline validation calls: 21 handlers doing Model.model_validate(console_ns.payload or {}) or parsing request.args by hand now get the validated model injected instead, same pattern as the earlier controllers/web migrations (#40796, #40856).

Left as-is on purpose:

  • the sync-draft endpoint, because it branches on Content-Type and also accepts text/plain, which the decorator doesn't cover
  • response-side model_validate(..., from_attributes=True) calls, which are serialization rather than request parsing

One behavior change: invalid payloads on these endpoints now return 422 from the decorator instead of surfacing a raw pydantic ValidationError. test_human_input_preview_rejects_non_mapping was updated to match.

From GitHub Copilot

Testing

  • Updated unit tests that call handlers directly (inspect.unwrap) to pass the explicitly-constructed validated model as the first argument:
    • api/tests/unit_tests/controllers/console/app/test_workflow.py
    • api/tests/unit_tests/controllers/console/app/test_workflow_convert_api.py
    • api/tests/unit_tests/controllers/console/app/test_workflow_human_input_debug_api.py
  • Local verification:
    • uv run --project api --dev pytest tests/unit_tests/controllers → 3884 passed
    • make lint → clean (ruff format/check, response-contract lint, import-linter, dotenv-linter)
    • make type-check → clean (pyrefly + mypy, 1719 source files, no issues)

Screenshots

Before After
N/A — backend-only controller refactor, no UI change N/A

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) to appease the lint gods. No frontend files changed, so vp staged (frontend) is not applicable.

…el_validate

Migrate the inline Model.model_validate(console_ns.payload or {}) and
request.args parsing in controllers/console/app/workflow.py to the
existing @model_validate decorator. The sync-draft endpoint keeps its
manual parsing because it branches on Content-Type to accept text/plain.
Unit tests that call the handlers directly now pass the validated model.

Ref langgenius#36659
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. refactor labels Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant