Guard genlocke data integrity edge cases

Block deletion of runs linked to a genlocke leg, prevent reactivating
completed/failed genlocke-linked runs, and guard encounter deletion
against genlocke transfer references with clear 400 errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Julian Tabel
2026-02-09 12:03:58 +01:00
parent d3b65e3c79
commit f0307f0625
4 changed files with 59 additions and 9 deletions

View File

@@ -159,6 +159,19 @@ async def delete_encounter(
if encounter is None:
raise HTTPException(status_code=404, detail="Encounter not found")
# Block deletion if encounter is referenced by a genlocke transfer
transfer_result = await session.execute(
select(GenlockeTransfer.id).where(
(GenlockeTransfer.source_encounter_id == encounter_id)
| (GenlockeTransfer.target_encounter_id == encounter_id)
)
)
if transfer_result.scalar_one_or_none() is not None:
raise HTTPException(
status_code=400,
detail="Cannot delete an encounter that is part of a genlocke transfer.",
)
await session.delete(encounter)
await session.commit()
return Response(status_code=204)