fix(materials): remove nested db.begin — material PATCH was 500
The router loads the material row (starting a transaction) before calling material_service.update_material, which then opened its own async with db.begin() → SQLAlchemy 'A transaction is already begun on this Session' → INTERNAL_ERROR on every PATCH (incl. changing the reference unit from ضرایب تبدیل). Mutations now run inside the request transaction committed by the get_db dependency.
This commit is contained in:
@@ -160,8 +160,12 @@ async def update_material(db: AsyncSession, material: Material, payload: Materia
|
|||||||
|
|
||||||
v2.5/2.6: category is DERIVED (from the first linked supplier) — it is
|
v2.5/2.6: category is DERIVED (from the first linked supplier) — it is
|
||||||
no longer part of the update payload.
|
no longer part of the update payload.
|
||||||
|
|
||||||
|
NOTE: no ``db.begin()`` here — the router already starts the transaction
|
||||||
|
(it loads the row first), and a nested begin raises
|
||||||
|
"A transaction is already begun on this Session" (500). The request
|
||||||
|
session commits via the get_db dependency.
|
||||||
"""
|
"""
|
||||||
async with db.begin():
|
|
||||||
if payload.name is not None:
|
if payload.name is not None:
|
||||||
duplicate = await db.scalar(
|
duplicate = await db.scalar(
|
||||||
select(Material.id).where(
|
select(Material.id).where(
|
||||||
|
|||||||
Reference in New Issue
Block a user