type request.args not match #21683

Closed
opened 2026-02-21 20:13:51 -05:00 by yindo · 1 comment
Owner

Originally created by @asukaminato0721 on GitHub (Jan 15, 2026).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

master

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

in the project, still many default=None, type=str there.

Example:

credential_id = request.args.get("credential_id", default=None, type=str)

✔️ Expected Behavior

Rewrite to BaseModel, similar to #30852

Actual Behavior

No response

Originally created by @asukaminato0721 on GitHub (Jan 15, 2026). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version master ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce in the project, still many `default=None, type=str` there. Example: ``` credential_id = request.args.get("credential_id", default=None, type=str) ``` ### ✔️ Expected Behavior Rewrite to BaseModel, similar to #30852 ### ❌ Actual Behavior _No response_
yindo added the 💪 enhancementgood first issue labels 2026-02-21 20:13:51 -05:00
yindo closed this issue 2026-02-21 20:13:51 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jan 15, 2026):

Using request.args.get with default=None, type=str is discouraged in Dify due to stricter type annotations in Werkzeug/Flask, which can cause type errors and make the code harder to maintain. The project now recommends defining a Pydantic BaseModel for your query or payload parameters, converting request.args to a dict, and validating with .model_validate(). For example:

from pydantic import BaseModel, Field

class CredentialQuery(BaseModel):
    credential_id: str | None = Field(default=None)

raw_args = request.args.to_dict()
query = CredentialQuery.model_validate(raw_args)
credential_id = query.credential_id

This approach improves type safety, validation, maintainability, and enables automatic API documentation generation. Recent PRs show this pattern is now standard in Dify, and the migration is nearly complete in the master branch—no current instances of the old pattern were found. For more details and examples, see issue #30852 and PR #30870.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Jan 15, 2026): <!-- Answer --> Using request.args.get with default=None, type=str is discouraged in Dify due to stricter type annotations in Werkzeug/Flask, which can cause type errors and make the code harder to maintain. The project now recommends defining a Pydantic BaseModel for your query or payload parameters, converting request.args to a dict, and validating with .model_validate(). For example: ```python from pydantic import BaseModel, Field class CredentialQuery(BaseModel): credential_id: str | None = Field(default=None) raw_args = request.args.to_dict() query = CredentialQuery.model_validate(raw_args) credential_id = query.credential_id ``` This approach improves type safety, validation, maintainability, and enables automatic API documentation generation. Recent PRs show this pattern is now standard in Dify, and the migration is nearly complete in the master branch—no current instances of the old pattern were found. For more details and examples, see [issue #30852](https://github.com/langgenius/dify/issues/30852) and [PR #30870](https://github.com/langgenius/dify/pull/30870). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/78aaceea-bb42-4664-b854-6f829e8a449f?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/78aaceea-bb42-4664-b854-6f829e8a449f?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/78aaceea-bb42-4664-b854-6f829e8a449f?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/78aaceea-bb42-4664-b854-6f829e8a449f?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/78aaceea-bb42-4664-b854-6f829e8a449f?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/78aaceea-bb42-4664-b854-6f829e8a449f?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/78aaceea-bb42-4664-b854-6f829e8a449f?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=Using%20request.args.get%20with%20default%3DNone%2C%20type%3Dstr%20is%20discouraged%20in%20Dify%20due%20to%20stricter%20type%20annotations%20in%20Werkzeug/Flask%2C%20which%20can%20cause%20type%20errors%20and%20make%20the%20code%20harder%20to%20maintain.%20The%20project%20now%20recommends%20defining%20a%20Pydantic%20BaseModel%20for%20your%20query%20or%20payload%20parameters%2C%20converting%20request.args%20to%20a%20dict%2C%20and%20validating%20with%20.model_validate%28%29.%20For%20example%3A%0A%0A%60%60%60python%0Afrom%20pydantic%20import%20BaseModel%2C%20Field%0A%0Aclass%20CredentialQuery%28BaseModel%29%3A%0A%20%20%20%20credential_id%3A%20str%20%7C%20None%20%3D%20Field%28default%3DNone%29%0A%0Araw_args%20%3D%20request.args.to_dict%28%29%0Aquery%20%3D%20CredentialQuery.model_validate%28raw_args%29%0Acredential_id%20%3D%20query.credential_id%0A%60%60%60%0A%0AThis%20approach%20improves%20type%20safety%2C%20validation%2C%20maintainability%2C%20and%20enables%20automatic%20API%20documentation%20generation.%20Recent%20PRs%20show%20this%20pattern%20is%20now%20standard%20in%20Dify%2C%20and%20the%20migration%20is%20nearly%20complete%20in%20the%20master%20branch%E2%80%94no%20current%20instances%20of%20the%20old%20pattern%20were%20found.%20For%20more%20details%20and%20examples%2C%20see%20%5Bissue%20%2330852%5D%28https%3A//github.com/langgenius/dify/issues/30852%29%20and%20%5BPR%20%2330870%5D%28https%3A//github.com/langgenius/dify/pull/30870%29.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/31077)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#21683