BUGFIX_STEP5.md
3.44 KB
Step5 Bug 修复报告
问题描述
错误信息:
AttributeError: 'IDMappingManager' object has no attribute 'get_mappings'. Did you mean: 'add_mapping'?
错误位置:
- 文件:scene_split_processor.py:648
- 方法:
_batch_update_settle_rule_goods_type_group_id
错误原因:
在批量更新表2的代码中,错误地调用了 self.id_mapper.get_mappings() 方法,但 IDMappingManager 类中没有这个方法。
问题分析
IDMappingManager 可用方法
查看 id_mapping_manager.py 发现,该类提供的方法有:
-
add_mapping(table_name, old_id, new_id, base_scene_code)- 添加映射 -
get_new_ids(table_name, old_id)- 获取所有新ID列表 -
get_new_id_by_scene(table_name, old_id, base_scene_code)- 根据场景获取新ID -
get_mapping_count(table_name)- 获取映射数量
错误代码
# 错误的调用方式
mappings = self.id_mapper.get_mappings(goods_type_group_table, old_id, base_scene_code)
if mappings:
new_goods_type_group_id = mappings[0]['new_id']
正确代码
# 正确的调用方式
new_goods_type_group_id = self.id_mapper.get_new_id_by_scene(goods_type_group_table, old_id, base_scene_code)
if new_goods_type_group_id:
# 使用 new_goods_type_group_id
修复方案
修改位置
文件: scene_split_processor.py:632-655
修改前:
# 从映射表查询新ID
mappings = self.id_mapper.get_mappings(goods_type_group_table, old_id, base_scene_code) # ❌ 错误
if mappings:
new_goods_type_group_id = mappings[0]['new_id']
修改后:
# 从映射表查询新ID
new_goods_type_group_id = self.id_mapper.get_new_id_by_scene(goods_type_group_table, old_id, base_scene_code) # ✅ 正确
if new_goods_type_group_id:
验证结果
测试命令
python main_scene_split.py --start-step=5 --end-step=5 --test-mode
测试结果
第5步:开始处理商品分组表
找到 0 条需要复制的表4记录
开始批量更新表2中的 goods_type_group_id...
开始批量更新表7中的 goods_type_group_id...
第5步完成,共复制 0 条记录
第 5 步执行成功
结果:
影响范围
受影响的方法
-
_batch_update_settle_rule_goods_type_group_id- 已修复✅
其他方法检查
检查了其他使用 id_mapper 的地方,确认都使用了正确的方法:
-
✅ add_mapping()- 正确使用 -
✅ get_new_id_by_scene()- 正确使用 -
✅ get_new_ids()- 正确使用 -
✅ get_mapping_count()- 正确使用
总结
问题根源
在实现批量优化时,错误地假设 IDMappingManager 有 get_mappings() 方法,实际上应该使用 get_new_id_by_scene() 方法。
修复内容
将 get_mappings() 调用改为 get_new_id_by_scene() 调用,并相应调整返回值的处理逻辑。
验证状态
-
✅ 代码修复完成 -
✅ 测试模式验证通过 -
✅ 无其他类似问题
建议
在生产环境部署前,建议:
- 先在测试环境用真实数据验证 Step5 的完整流程
- 确认批量插入和批量更新都能正常工作
- 验证映射关系的正确性
修复状态:
修复日期: 2026-05-10
影响版本: v1.0
修复版本: v1.1