diff --git a/thallium-backend/src/routes/orders.py b/thallium-backend/src/routes/orders.py index af659bd..6c6e76b 100644 --- a/thallium-backend/src/routes/orders.py +++ b/thallium-backend/src/routes/orders.py @@ -21,8 +21,6 @@ async def create_order(request: Request, db: DBSession, client: PrintfulClient, If the voucher does not have enough funds, the order is cancelled. """ voucher: Voucher = request.state.voucher - stmt = select(DBVoucher).where(DBVoucher.id == voucher.id).with_for_update() - db_voucher = await db.scalar(stmt) resp = await client.post( "/orders/estimate-costs", @@ -30,6 +28,9 @@ async def create_order(request: Request, db: DBSession, client: PrintfulClient, params={"confirm": False}, ) resp.raise_for_status() + + stmt = select(DBVoucher).where(DBVoucher.id == voucher.id).with_for_update() + db_voucher = await db.scalar(stmt) cost = OrderCosts.model_validate(resp.json()["result"]["costs"]) if cost.total > db_voucher.balance: raise HTTPException(