[Refactor/Chore] avoid pass dict, directly pass basemodel #21881

Open
opened 2026-02-21 20:14:42 -05:00 by yindo · 3 comments
Owner

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

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for refactors or chores; 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.

Description

since we now use basemodel, we can pass them around.

Motivation

less parameter

Additional Context

No response

Originally created by @asukaminato0721 on GitHub (Jan 25, 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 refactors or chores; 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. ### Description since we now use basemodel, we can pass them around. ### Motivation less parameter ### Additional Context _No response_
yindo added the good first issue🙏 help wanted labels 2026-02-21 20:14:42 -05:00
Author
Owner

@asukaminato0721 commented on GitHub (Jan 25, 2026):

Some models will have circular import, so move them in one place will be next step.

@asukaminato0721 commented on GitHub (Jan 25, 2026): Some models will have circular import, so move them in one place will be next step.
Author
Owner

@fghpdf commented on GitHub (Jan 25, 2026):

I've started working on this issue and submitted an initial PR #31514 with the following refactorings:

Completed

  1. RagPipelineTransformService._deal_knowledge_index() - Changed retrieval_model parameter from dict to RetrievalSetting | None
  2. RagPipelineDslService.get_leaked_dependencies() - Changed dsl_dependencies from list[dict] to list[PluginDependency]
  3. AppDslService.get_leaked_dependencies() - Same pattern as above

All tests pass and type checking is clean.

Pattern Applied

The refactoring follows this pattern:

  • Find functions accepting dict parameters that immediately call Model.model_validate()
  • Change parameter type to the actual BaseModel type
  • Move validation to the call site (where data comes from database/external sources)
  • Remove redundant validation inside the function

This is an incremental approach. More opportunities exist in the codebase - I can continue with additional PRs if this approach looks good to the maintainers.

cc @asukaminato0721

@fghpdf commented on GitHub (Jan 25, 2026): I've started working on this issue and submitted an initial PR #31514 with the following refactorings: ## Completed 1. **RagPipelineTransformService._deal_knowledge_index()** - Changed `retrieval_model` parameter from `dict` to `RetrievalSetting | None` 2. **RagPipelineDslService.get_leaked_dependencies()** - Changed `dsl_dependencies` from `list[dict]` to `list[PluginDependency]` 3. **AppDslService.get_leaked_dependencies()** - Same pattern as above All tests pass and type checking is clean. ## Pattern Applied The refactoring follows this pattern: - Find functions accepting `dict` parameters that immediately call `Model.model_validate()` - Change parameter type to the actual BaseModel type - Move validation to the call site (where data comes from database/external sources) - Remove redundant validation inside the function This is an incremental approach. More opportunities exist in the codebase - I can continue with additional PRs if this approach looks good to the maintainers. cc @asukaminato0721
Author
Owner

@asukaminato0721 commented on GitHub (Jan 25, 2026):

@fghpdf

igtm, feel free to go ahead.

@asukaminato0721 commented on GitHub (Jan 25, 2026): @fghpdf igtm, feel free to go ahead.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#21881