Fix&Feat: Template config optimization#8228
Conversation
There was a problem hiding this comment.
Code Review
This pull request enhances the configuration system by adding support for template_list schema navigation in the backend and improving the WebUI's display of template entries. Key changes include updating get_schema_item to handle nested template paths, introducing display_item and hide_hint_in_list properties for better template entry identification in the UI, and adding unit tests for these new behaviors. Feedback was provided regarding a potential AttributeError in the schema utility when handling malformed templates fields, along with a suggested fix to ensure robust dictionary type checking.
| template_meta = meta.get("templates", {}).get(parts[idx + 2]) | ||
| if not isinstance(template_meta, dict): | ||
| return None |
There was a problem hiding this comment.
The current implementation of get_schema_item is not fully defensive when handling template_list types. If the templates field in the schema exists but is not a dictionary (e.g., it is None or a string due to a malformed schema), meta.get("templates", {}) will return that non-dictionary value, and the subsequent .get() call will raise an AttributeError. It is safer to explicitly verify that templates is a dictionary before attempting to access its keys.
| template_meta = meta.get("templates", {}).get(parts[idx + 2]) | |
| if not isinstance(template_meta, dict): | |
| return None | |
| templates = meta.get("templates") | |
| if not isinstance(templates, dict): | |
| return None | |
| template_meta = templates.get(parts[idx + 2]) | |
| if not isinstance(template_meta, dict): | |
| return None |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
get_schema_itemlogic for handlingtemplate_listpaths is getting fairly complex with index arithmetic and nested branching; consider extracting thetemplate_list-specific traversal into a small helper or restructuring the loop to make the supported path shapes and failure cases easier to read and maintain. - In
TemplateListEditor.vue, bothgetItemMetaBySelectorandgetValueBySelectorimplement their own selector parsing; consolidating this dot-path traversal into a single shared helper would reduce the risk of subtle inconsistencies if the selector semantics evolve.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `get_schema_item` logic for handling `template_list` paths is getting fairly complex with index arithmetic and nested branching; consider extracting the `template_list`-specific traversal into a small helper or restructuring the loop to make the supported path shapes and failure cases easier to read and maintain.
- In `TemplateListEditor.vue`, both `getItemMetaBySelector` and `getValueBySelector` implement their own selector parsing; consolidating this dot-path traversal into a single shared helper would reduce the risk of subtle inconsistencies if the selector semantics evolve.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Modifications / 改动点
解决的问题
更改文件
dashboard/src/components/shared/TemplateListEditor.vue
dashboard/src/components/shared/AstrBotConfigV4.vue
astrbot/dashboard/routes/util.py
template_list.templates.<template>.items路径。astrbot/dashboard/routes/config.py
tests/unit/test_dashboard_util.py
docs/zh/dev/star/guides/plugin-config.md
docs/en/dev/star/guides/plugin-config.md
Screenshots or Test Results / 运行截图或测试结果
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
Optimize template-based configuration handling and display in the dashboard, particularly for file-type fields and plugin-driven configs.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests:
Summary by Sourcery
Optimize template-based configuration handling and display for plugin configs, especially around template_list entries and file-type fields.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: