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

@ -4,5 +4,6 @@
"Bash(git add *)", "Bash(git add *)",
"Bash(git commit *)" "Bash(git commit *)"
] ]
} },
"$version": 3
} }

8
.qwen/settings.json.orig Normal file
View File

@ -0,0 +1,8 @@
{
"permissions": {
"allow": [
"Bash(git add *)",
"Bash(git commit *)"
]
}
}

Binary file not shown.

View File

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

View File

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

View File

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