Skip to content

Conversation

@asukaminato0721
Copy link
Contributor

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

part of #28015

Screenshots

Before After
... ...

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 && npx lint-staged (frontend) to appease the lint gods

@asukaminato0721 asukaminato0721 changed the title port api/controllers/console/app/workflow.py refactor: port api/controllers/console/app/workflow.py Jan 7, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @asukaminato0721, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the workflow controller's API response handling by adopting Pydantic models for data serialization. This modernization effort aims to improve the robustness, maintainability, and clarity of API responses, ensuring better data consistency and validation across the application.

Highlights

  • Pydantic Migration: The core change involves migrating API response serialization from flask_restx.fields to Pydantic models, enhancing type safety and data validation for various workflow-related entities.
  • New Response Models: Introduced several new Pydantic ResponseModel classes, including SimpleAccount, SimpleEndUser, EnvironmentVariable, ConversationVariable, PipelineVariable, WorkflowResponse, WorkflowPaginationResponse, and WorkflowRunNodeExecutionResponse.
  • API Endpoint Updates: Existing API endpoints in workflow.py have been updated to utilize the new Pydantic response schemas and a helper function _dump_response for serialization, replacing the marshal_with decorators.
  • Enhanced Testing: A new unit test file has been added to specifically validate the correct serialization behavior of the new Pydantic response models, including masking of secret environment variables.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@asukaminato0721 asukaminato0721 marked this pull request as ready for review January 7, 2026 07:15
Copilot AI review requested due to automatic review settings January 7, 2026 07:15
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jan 7, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the api/controllers/console/app/workflow.py file to use Pydantic models for request and response validation and serialization, replacing the previous flask_restx field definitions. This is a great improvement for type safety and maintainability. The changes are well-implemented, and the addition of unit tests for the new response models is much appreciated.

I have a couple of suggestions to further improve the code by reducing duplication and ensuring consistency. Please see my comments below.

Copy link
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

This PR refactors api/controllers/console/app/workflow.py by migrating from flask-restx field definitions to Pydantic models for response serialization. This is part of a broader effort (#28015) to align API models with request parsers across the codebase.

Key Changes:

  • Replaced flask-restx fields and marshal_with decorators with Pydantic ResponseModel classes
  • Introduced custom serialization logic for environment variables (with secret masking) and conversation variables
  • Added comprehensive unit tests for the new Pydantic response models

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
api/controllers/console/app/workflow.py Replaced flask-restx field definitions with Pydantic models (WorkflowResponse, WorkflowPaginationResponse, WorkflowRunNodeExecutionResponse), added helper classes (SimpleAccount, SimpleEndUser, EnvironmentVariable, ConversationVariable, PipelineVariable), and implemented custom serialization with _dump_response() function
api/tests/unit_tests/controllers/console/app/test_workflow_response_models.py Added unit tests for the new Pydantic response models, testing secret variable masking, nested entity serialization, and pagination response handling

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

Comment on lines +843 to +844
if not workflow:
return None
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The API documentation at line 827 indicates this endpoint returns a WORKFLOW_RESPONSE_SCHEMA on 200, but the implementation can return None (line 844). This creates an inconsistency between the documented API schema and actual behavior. The endpoint should either always return a WorkflowResponse schema (and raise a 404 when not found, similar to DraftWorkflowApi.get), or the response documentation should be updated to indicate it can return null/None.

Copilot uses AI. Check for mistakes.
asukaminato0721 and others added 4 commits January 7, 2026 16:39
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@asukaminato0721
Copy link
Contributor Author

/gemini review

@gemini-code-assist
Copy link
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


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

Comment on lines +833 to +835
if not workflow:
return None
return _dump_response(WorkflowResponse, workflow)
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The endpoint returns None when the published workflow is not found, but the API response schema at line 817 documents that a 404 response should be returned for "Published workflow not found". The behavior should be consistent with other similar endpoints like DraftWorkflowApi.get (line 426-427) which raises DraftWorkflowNotExist instead of returning None. Consider raising an appropriate NotFound exception instead of returning None.

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

size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant