fix(warehouse): fix 500 error on delete by extracting attributes before db commit

This commit is contained in:
DXC
2026-04-02 10:31:53 +08:00
parent 4b023a4002
commit 457e222632
6 changed files with 19 additions and 7 deletions

View File

@ -171,10 +171,13 @@ def delete_location(location_id):
"""
try:
location = SysWarehouseLocation.query.get(location_id)
if not location:
return jsonify({'code': 404, 'msg': '库位不存在', 'data': None})
# 在删除前提取属性,避免 commit 后访问已删除对象
location_code = location.location_code
# 递归删除所有子库位
def delete_recursive(loc):
# 先删除所有子节点
@ -183,14 +186,14 @@ def delete_location(location_id):
delete_recursive(child)
# 再删除自身
db.session.delete(loc)
delete_recursive(location)
db.session.commit()
return jsonify({
'code': 200,
'msg': '删除成功',
'location_code': location.location_code
'location_code': location_code
})
except Exception as e:
db.session.rollback()

View File

@ -1,6 +1,6 @@
{
"label_printer": {
"ip": "172.16.0.119",
"ip": "192.168.9.14",
"port": 9100
},
"network_printer": {

View File

@ -1,7 +1,7 @@
import socket
# ================= 配置区域 =================
PRINTER_IP = '192.168.9.89'
PRINTER_IP = '192.168.9.101'
PRINTER_PORT = 9100