refactor(core): 1062 唯一键冲突判定收口至 core/db_errors
六个 service 各自复制的 _is_duplicate_entry(口径已漂移:rating/product 用 _ERR_DUP_ENTRY 常量、其余四处写字面量 1062)收敛为共享函数; is_duplicate_entry 语义与文案注释各处保留,非 1062 完整性错误仍原样 上抛由全局处理器收敛。 Co-Authored-By: Claude Code <noreply@anthropic.com>
这个提交包含在:
1 父节点
5a3778a424
当前提交
a0086554b1
7 个文件已更改
+31
-19
没有与搜索条件相匹配的文件
@@ -35,6 +35,7 @@ from app.core.constants import (
|
||||
MODULE_SHIPMENT,
|
||||
NO_PREFIX_SHIPMENT,
|
||||
)
|
||||
from app.core.db_errors import is_duplicate_entry
|
||||
from app.core.exceptions import BadRequestError, NotFoundError
|
||||
from app.core.response import PageResult
|
||||
from app.models import Business, Shipment, ShipmentItem, User
|
||||
@@ -144,8 +145,7 @@ def _ensure_business_writable(session: Session, business_id: int, action: str) -
|
||||
|
||||
def _is_duplicate_entry(exc: IntegrityError) -> bool:
|
||||
"""识别 MySQL 唯一键冲突(1062),与 business/receipt_service 同口径。"""
|
||||
args = getattr(exc.orig, "args", ())
|
||||
return bool(args) and args[0] == 1062
|
||||
return is_duplicate_entry(exc)
|
||||
|
||||
|
||||
def list_shipments(session: Session, query: ShipmentQuery) -> PageResult[ShipmentOut]:
|
||||
|
||||
在新工单中引用
屏蔽一个用户