BookSystem/.trae/documents/bug_fix_plan_v5.md
jayhgq 6f4ace886f fix(roles): 修复角色创建时 model_dump 错误
修复角色创建时出现的 AttributeError: 'dict' object has no attribute 'model_dump' 错误,将 role_data.model_dump() 改为 dict(role_data) 以兼容 Pydantic v1 和 v2。

同时优化了搜索布局和样式,确保查询条件和按钮在同一行显示:

1. 修改 admin-crud.css 添加搜索区域不换行样式
2. 调整 role-crud.ts 中的 search 配置
3. 将 GET 查询接口改为 POST /search 方式
4. 修复角色权限分配时的权限加载问题
2026-05-09 17:59:10 +08:00

29 lines
904 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Bug 修复计划版本5
## 问题描述
添加角色时,后台报错误:`AttributeError: 'dict' object has no attribute 'model_dump'`
## 分析
这个错误说明 `role_data` 已经是一个字典dict而不是 Pydantic 模型对象。这可能是因为:
1. **Pydantic 版本问题**:在 Pydantic v1 中使用 `dict()` 方法,而在 Pydantic v2 中使用 `model_dump()` 方法
2. FastAPI 解析问题:请求格式不正确导致无法正确解析为 Pydantic 模型
## 修改步骤
修改 `backend/auth/apps/roles/urls.py` 文件,将 `role_data.model_dump()` 改为 `dict(role_data)`,这是兼容 Pydantic v1 和 v2 的写法。
## 修改文件清单
| 文件 | 修改内容 |
|------|----------|
| `backend/auth/apps/roles/urls.py` | 将 `role_data.model_dump()` 改为 `dict(role_data)` |
## 预期结果
修改后,创建角色功能应该正常工作。