修复 ObjectEditor中因索引错位导致误报"键名已存在"的 bug#6739
Conversation
Summary of ChangesHello, 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! 此拉取请求旨在解决 Highlights
Using Gemini Code AssistThe 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
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 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. Footnotes
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
_originalKeyfield is being added ad hoc onpairat focus time; consider making this an explicit property on the key-value objects (or managed in a separate map) so future code doesn’t inadvertently rely on or mutate hidden state. - After
onKeyBlurcompletes, consider clearingpair._originalKeyto avoid stale values affecting later programmatic key changes that might not go through a new focus event. - You might want to rename
onKeyBlurto something likeonKeyBlurValidateAndApply(or similar) to reflect that it performs both validation and template-driven updates, making the intent clearer at the call site.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `_originalKey` field is being added ad hoc on `pair` at focus time; consider making this an explicit property on the key-value objects (or managed in a separate map) so future code doesn’t inadvertently rely on or mutate hidden state.
- After `onKeyBlur` completes, consider clearing `pair._originalKey` to avoid stale values affecting later programmatic key changes that might not go through a new focus event.
- You might want to rename `onKeyBlur` to something like `onKeyBlurValidateAndApply` (or similar) to reflect that it performs both validation and template-driven updates, making the intent clearer at the call site.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
本次 PR 修复了 ObjectEditor 组件中因数组索引错位导致的“键名已存在”误报 bug,实现方式清晰且有效。通过在 focus 事件中暂存原始键名,并在 blur 事件中直接操作 pair 对象,避免了之前因 nonTemplatePairs 过滤后索引不一致引发的问题,代码也更具可读性和健壮性。
另外,在审查代码时,我注意到 updateJSON 函数(第 357-364 行)似乎存在与本次修复的 bug 类似的索引问题。它在处理 JSON 字段验证时也使用了来自 v-for 的 index,这可能在某些情况下导致错误。建议可以在后续的 PR 中一并修复此问题。
除此之外,我对 onKeyBlur 函数中的 alert() 使用提出了一点改进建议,以提升用户体验。
| const isKeyExists = localKeyValuePairs.value.some(p => p !== pair && p.key === newKey) | ||
| if (isKeyExists) { | ||
| // 如果键名已存在,提示用户并恢复原值 | ||
| alert(t('core.common.objectEditor.keyExists')) |
Use generated ids for key-value pairs instead of array indexes to prevent mismatch issues during editing and rendering. Also replace duplicate-key alerts with toast warnings for a more consistent UI experience.
修复 ObjectEditor 组件中,选中自定义请求体参数的 key输入框后点击其他位置会误弹"键名已存在"提示的 bug。
Modifications / 改动点
nonTemplatePairs 是 localKeyValuePairs过滤模板字段后的子数组,v-for 的 index与原始数组索引不对应。updateKey用错误的索引去原始数组查找originalKey,导致误判键名重复。
Screenshots or Test Results / 运行截图或测试结果
原来的问题:

改后解决了此问题
验证步骤:
打开模型提供商配置,点击自定义请求体参数的"修改"按钮
点击已有 key 的输入框(如frequency_penalty),使其获得焦点
不做任何修改,点击对话框外的空白区域或切换桌面
预期结果:不再弹出"键名已存在"提示而是正常退出
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Fix key rename handling in ObjectEditor to avoid false "key already exists" warnings when blurring key fields.
Bug Fixes:
Enhancements: