Skip to content

refactor(api): migrate console site responses to BaseModel#35217

Open
ai-hpc wants to merge 4 commits intolanggenius:mainfrom
ai-hpc:refactor/migrate-console-app-import-response-28015
Open

refactor(api): migrate console site responses to BaseModel#35217
ai-hpc wants to merge 4 commits intolanggenius:mainfrom
ai-hpc:refactor/migrate-console-app-import-response-28015

Conversation

@ai-hpc
Copy link
Copy Markdown
Contributor

@ai-hpc ai-hpc commented Apr 14, 2026

Part of #28015

Summary

Migrate response marshalling in api/controllers/console/app/app_import.py from Flask-RESTX response models to Pydantic BaseModel/ResponseModel schemas registered with register_schema_models().

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 and make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. refactor labels Apr 14, 2026
@ai-hpc ai-hpc requested a review from QuantumGhost as a code owner April 14, 2026 21:06
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Apr 14, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

No changes detected.

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

No changes detected.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates the console app import endpoints in api/controllers/console/app/app_import.py from Flask-RESTX response models to Pydantic BaseModel/ResponseModel schemas registered via register_schema_models(), aligning response documentation and serialization with the newer schema approach used elsewhere in the console API.

Changes:

  • Added Pydantic response schemas (AppImportResponse, AppImportCheckDependenciesResponse, LeakedDependencyResponse) and registered them with console_ns.
  • Updated RESTX @response decorators to reference the new schema models.
  • Updated endpoint return paths to validate into response models before model_dump(mode="json").

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +39 to +42
class LeakedDependencyResponse(ResponseModel):
type: str
value: Any
current_identifier: str | None = None
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LeakedDependencyResponse.value is annotated as Any, but when validating from CheckDependenciesResult it will receive PluginDependency.value objects (nested Pydantic models). To avoid accidentally returning a non-JSON-serializable object (depending on how Any is serialized), consider normalizing value to a plain dict (e.g., type it as dict[str, Any] and/or add a validator that converts BaseModel values via model_dump(mode="json")).

Copilot uses AI. Check for mistakes.
result = import_service.check_dependencies(app_model=app_model)

return result.model_dump(mode="json"), 200
return AppImportCheckDependenciesResponse.model_validate(result).model_dump(mode="json"), 200
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppImportCheckDependenciesResponse.model_validate(result) relies on attribute access; if check_dependencies() ever returns a dict/model_dump()-style object (as some tests/mocks do), this will fail. A more robust approach is to validate from result.model_dump(mode="json") (or from the dict directly) before dumping the response.

Suggested change
return AppImportCheckDependenciesResponse.model_validate(result).model_dump(mode="json"), 200
result_data = result if isinstance(result, dict) else result.model_dump(mode="json")
return AppImportCheckDependenciesResponse.model_validate(result_data).model_dump(mode="json"), 200

Copilot uses AI. Check for mistakes.
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.

2 participants