M16: isolate acceptance and harden readiness

This commit is contained in:
NuklearRabbit
2026-08-10 12:08:42 +02:00
parent 2ee8b2d82b
commit 686795a452
13 changed files with 200 additions and 41 deletions
+7 -5
View File
@@ -18,12 +18,14 @@ from app.models.vehicle import Vehicle
from app.schemas import CurrentUser, RegisterReturnRequest
from app.services.audit import record_audit_event
REF_PREFIX = "INSP"
def _new_inspection_ref() -> str:
"""Generate a collision-resistant public reference without reading mutable counts.
def _next_public_ref(db: Session) -> str:
existing = db.execute(select(Inspection.public_ref)).scalars().all()
return f"{REF_PREFIX}-{len(existing) + 1:04d}"
Return commands for different bookings can commit concurrently. A count-based
reference made those independent transactions race for the same unique value.
"""
return f"INSP-{uuid.uuid4().hex[:10].upper()}"
def _derive_vehicle_status_with_reason(
@@ -211,7 +213,7 @@ def register_vehicle_return(
evaluation = evaluate_return(db, booking, vehicle, body, now=now)
inspection = Inspection(
public_ref=_next_public_ref(db),
public_ref=_new_inspection_ref(),
booking_id=booking.id,
vehicle_id=vehicle.id,
type="return",