1
0
forked from erp-dev/erp
Files
erpnew/docs/bug-fix-20251122-stateflow.md

57 lines
2.0 KiB
Markdown
Raw Permalink 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 修复报告
## 基本信息
- 日期2025-11-22
- 模块stateflow流程状态管理
- 修复者Cline
---
## 问题描述
API `GET /api/v1/stateflow/business-objects/xxx/state-logs/` 无法获取已撤销状态的工艺参数。
**具体表现**当一个状态流转记录被撤销后通过该API获取状态日志列表时已撤销状态记录的工艺参数会被过滤掉导致参数丢失。
**影响范围**
1. 使用 `GET /api/v1/stateflow/business-objects/xxx/state-logs/` API 获取包含已撤销状态的日志列表
2. 依赖这些日志进行审计、回溯或数据分析的功能
---
## 根本原因
`StateFlowRecordWithParametersSerializer` 中调用 `get_all_parameters_summary()` 时未传递 `include_cancelled=True` 参数,导致已撤销状态的参数被 `get_all_parameters_summary()` 方法内部逻辑过滤掉。
---
## 修复方案
修改 `/home/f/coding/flower/stateflow/serializers.py` 中的 `get_parameters_summary` 方法:
**修改前**
```python
def get_parameters_summary(self, obj):
"""获取参数摘要"""
return obj.get_all_parameters_summary()
```
**修改后**
```python
def get_parameters_summary(self, obj):
"""获取参数摘要,包含已撤销状态的参数"""
return obj.get_all_parameters_summary(include_cancelled=True)
```
---
## 测试验证
1. **创建测试用例**:在 `/home/f/coding/flower/stateflow/tests/test_business_object_api.py` 中创建 `test_get_state_logs_api_cancelled_state_with_parameters` 测试用例用于复现和验证bug。
2. **验证修复**
- 运行测试用例 `test_get_state_logs_api_cancelled_state_with_parameters`
- 修复前测试失败,修复后测试通过
- 验证已撤销状态的工艺参数能够正确返回
---
## 总结
该修复确保了已撤销状态的工艺参数不会丢失与未撤销状态的处理方式保持一致符合业务需求。修复仅涉及一行代码的修改但确保了数据完整性和API的一致性。