[Bug] Persona folder rename moves to root and loses description unexpectedly
What happened / 发生了什么
Renaming a nested persona folder in the WebUI moves it to the root folder. If the folder has a description, it may be cleared during rename.
Reproduce / 如何复现?
Steps to Reproduce
- Open Persona Manager in the WebUI.
- Create folder "1" in the root.
- Create folder "2" inside "1".
- Create folder "3" inside "2", write some description in folder "3".
- Rename folder "3" to any name (e.g., "4").
Expected Result
- The folder remains under its original parent.
- The description remains unchanged.
Actual Result
- The folder is moved to the root level.
- The description is cleared if it previously existed.
AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器
- OS: Windows
- Date: 2026-05-03
- AstrBot version: 4.23.6
- UI: Persona Manager (WebUI)
OS
Windows
Logs / 报错日志
- Create folder "3" inside "2", write some description in folder "3".
- Result of 1, now 3 is in 2 and has some description.
- Rename folder "3" to any name (e.g., "4").
- After the renaming, folder "4" is moved to the root level unexpectedly.
- After the renaming, folder "4" loses all its description.
Are you willing to submit a PR? / 你愿意提交 PR 吗?
- [x] Yes!
Code of Conduct
- [x] I have read and agree to abide by the project's Code of Conduct。
Hi @Fronut! I'm Dosu and I’m helping the AstrBot team.
感谢详细的复现步骤!这个 bug 的根因已经定位到了。
根本原因: 前端的重命名操作只发送了 folder_id 和 name,没有携带 parent_id 和 description。后端 API handler 使用 data.get("parent_id") / data.get("description") 读取这些字段,缺失时返回 None,然后被数据库层解释为"显式设为 NULL",导致文件夹移到根目录并清除描述。
涉及两处前端代码:
后端数据库层其实已经实现了 NOT_GIVEN 哨兵模式来跳过未提供的字段 [3],但 API handler 层没有正确使用它 [4]。
推荐修复方式(二选一):
- 修前端(推荐)— 重命名时同时发送现有的
parent_id和description:
await personaStore.updateFolder({
folder_id: this.renamingFolder.folder_id,
name: this.newFolderName,
parent_id: this.renamingFolder.parent_id,
description: this.renamingFolder.description,
});
- 修后端 — API handler 中对缺失字段使用
NOT_GIVEN哨兵而非None:
parent_id = data.get("parent_id") if "parent_id" in data else NOT_GIVEN
description = data.get("description") if "description" in data else NOT_GIVEN
推荐方案 1,因为更明确且不改变后端 API 契约。既然你愿意提交 PR,以上信息应该够用了!
To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
后端数据库层其实已经实现了
NOT_GIVEN哨兵模式来跳过未提供的字段 [3],但 API handler 层没有正确使用它 [4]。
如这个AI @dosu 所述,后端数据库实现了NOT_GIVEN哨兵模式,但是没有被API handler层正确地使用,所以显然我们更应该使用后端的修理方式,而不是前端的修复方式。同时,前端将没有修改的参数原封不动传回来的做法也不显得很合理。API 的 PATCH 语义应该是:没传的字段不应被修改。这是服务端责任,不是客户端责任。
你说得对,这确实应该是服务端的责任。PATCH 语义下,未传的字段不应被修改,后端已经通过 NOT_GIVEN 哨兵具备了这个能力 [1],只是 API handler 层没有正确衔接。
修复方式很直接 — 在 persona.py 的 update_folder 中,对可选字段用 "key" in data 判断是否传入,未传入时使用 NOT_GIVEN [2]:
from astrbot.core.sentinels import NOT_GIVEN
parent_id = data.get("parent_id") if "parent_id" in data else NOT_GIVEN
description = data.get("description") if "description" in data else NOT_GIVEN
sort_order = data.get("sort_order") if "sort_order" in data else NOT_GIVEN
这样数据库层已有的三态逻辑(NOT_GIVEN = 不更新,None = 置空,其他 = 更新为该值)就能被正确利用,前端也不需要做额外处理。
To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.