x
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
from fastapi import APIRouter, Depends, Query, HTTPException
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select, update, func
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from typing import Optional, List
|
||||
|
||||
from shared.database.database import get_db_session
|
||||
@@ -114,7 +115,12 @@ async def create_inventory(
|
||||
location=payload.location
|
||||
)
|
||||
db_session.add(inventory)
|
||||
await db_session.commit()
|
||||
try:
|
||||
await db_session.commit()
|
||||
except IntegrityError:
|
||||
# 并发创建命中 (product_id, warehouse_id) 唯一约束
|
||||
await db_session.rollback()
|
||||
raise HTTPException(status_code=400, detail="该仓库已存在该物料库存记录")
|
||||
await db_session.refresh(inventory)
|
||||
|
||||
return InventoryResponse(
|
||||
|
||||
Reference in New Issue
Block a user