Skip to content

修复 ObjectEditor中因索引错位导致误报"键名已存在"的 bug#6739

Merged
RC-CHN merged 3 commits intoAstrBotDevs:masterfrom
Reisenbug:fix/object-editor-key-index
Mar 24, 2026
Merged

修复 ObjectEditor中因索引错位导致误报"键名已存在"的 bug#6739
RC-CHN merged 3 commits intoAstrBotDevs:masterfrom
Reisenbug:fix/object-editor-key-index

Conversation

@Reisenbug
Copy link
Contributor

@Reisenbug Reisenbug commented Mar 21, 2026

修复 ObjectEditor 组件中,选中自定义请求体参数的 key输入框后点击其他位置会误弹"键名已存在"提示的 bug。

Modifications / 改动点

nonTemplatePairs 是 localKeyValuePairs过滤模板字段后的子数组,v-for 的 index与原始数组索引不对应。updateKey用错误的索引去原始数组查找originalKey,导致误判键名重复。

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

原来的问题:
image
改后解决了此问题
验证步骤:
打开模型提供商配置,点击自定义请求体参数的"修改"按钮
点击已有 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.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.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:

  • Preserve and compare the original key on focus to prevent spurious duplicate-key alerts when a key input loses focus without changes.

Enhancements:

  • Simplify key update logic in ObjectEditor by operating on the key-value pair object directly instead of relying on list indices.

@auto-assign auto-assign bot requested review from Fridemn and advent259141 March 21, 2026 06:02
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 21, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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!

此拉取请求旨在解决 ObjectEditor 组件中一个关键的用户体验问题,即在编辑对象属性时,由于内部索引处理不当,导致键名重复的错误提示。通过重新设计键名更新和验证的机制,确保了系统能够准确识别键名的实际变化,从而消除了误报,使参数编辑流程更加流畅和直观。

Highlights

  • 修复 ObjectEditor 中的键名重复误报问题: 解决了 ObjectEditor 组件中,当用户选中自定义请求体参数的键输入框后,即使未修改键名,点击其他位置也会错误地弹出“键名已存在”提示的 bug。
  • 优化键名更新逻辑: 重构了键名更新的逻辑,将原有的 updateKey 函数替换为 onKeyBlur。新的实现通过在输入框获取焦点时存储原始键,并在失焦时直接操作 pair 对象,避免了因 v-for 索引错位导致的问题。
  • 改进用户体验: 通过修复此 bug,提升了 ObjectEditor 组件的用户体验,确保键名验证的准确性,避免了不必要的错误提示。
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.

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.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added the area:webui The bug / feature is about webui(dashboard) of astrbot. label Mar 21, 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

本次 PR 修复了 ObjectEditor 组件中因数组索引错位导致的“键名已存在”误报 bug,实现方式清晰且有效。通过在 focus 事件中暂存原始键名,并在 blur 事件中直接操作 pair 对象,避免了之前因 nonTemplatePairs 过滤后索引不一致引发的问题,代码也更具可读性和健壮性。

另外,在审查代码时,我注意到 updateJSON 函数(第 357-364 行)似乎存在与本次修复的 bug 类似的索引问题。它在处理 JSON 字段验证时也使用了来自 v-forindex,这可能在某些情况下导致错误。建议可以在后续的 PR 中一并修复此问题。

除此之外,我对 onKeyBlur 函数中的 alert() 使用提出了一点改进建议,以提升用户体验。

const isKeyExists = localKeyValuePairs.value.some(p => p !== pair && p.key === newKey)
if (isKeyExists) {
// 如果键名已存在,提示用户并恢复原值
alert(t('core.common.objectEditor.keyExists'))
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

为了提供更好的用户体验,建议避免使用 alert()alert() 是一个阻塞式对话框,会中断用户操作流,且其样式无法与应用的 UI 保持统一。可以考虑使用 Vuetify 的 v-snackbar 组件来显示非侵入式的提示,或者像处理 JSON 验证错误那样,通过在 v-text-field 下方显示错误信息来通知用户。这样可以使错误提示更友好,也更符合整体设计。

Reisenbug and others added 2 commits March 21, 2026 14:15
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.
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Mar 24, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 24, 2026
@RC-CHN RC-CHN merged commit 7305d46 into AstrBotDevs:master Mar 24, 2026
7 checks passed
@Reisenbug Reisenbug deleted the fix/object-editor-key-index branch March 24, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants