fix: Isolate evaluator dynamic configs#396
Merged
e06084 merged 1 commit intoMigoXLab:mainfrom Apr 29, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request ensures configuration isolation by performing deep copies of dynamic configurations when setting rules and LLMs, preventing unintended shared state between objects. I have suggested using Pydantic's built-in model_copy(deep=True) method instead of the standard library's copy.deepcopy, which is more idiomatic and efficient for Pydantic models. Adopting this approach will also allow for the removal of the unnecessary copy import.
| if not rule_config: | ||
| return | ||
| config_default = getattr(rule, 'dynamic_config') | ||
| config_default = copy.deepcopy(getattr(rule, 'dynamic_config')) |
Contributor
There was a problem hiding this comment.
建议使用 Pydantic 提供的 model_copy(deep=True) 方法来替代 copy.deepcopy(getattr(...))。由于 rule.dynamic_config 是一个 Pydantic 模型,使用其内置的拷贝方法更加高效且符合惯用法。此外,直接访问属性比使用 getattr 字符串更清晰。
Suggested change
| config_default = copy.deepcopy(getattr(rule, 'dynamic_config')) | |
| config_default = rule.dynamic_config.model_copy(deep=True) |
| if not llm_config: | ||
| return | ||
| config_default = getattr(llm, 'dynamic_config') | ||
| config_default = copy.deepcopy(getattr(llm, 'dynamic_config')) |
Contributor
e06084
added a commit
that referenced
this pull request
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
此前配置注入会直接复用 evaluator 类上的
dynamic_config对象。当多个 evaluator 实例分别设置不同配置时,后一次配置可能覆盖前一次配置,并污染类上的默认配置。
本 PR 先修复配置对象共享污染问题,为后续支持
LLMCustomRule做基础准备。变更内容
Model.set_config_rule()中,应用用户配置前先 deepcopy 默认dynamic_config。Model.set_config_llm()中,同样先 deepcopy 默认dynamic_config,再应用用户配置。测试