From 28e7a3e3d299e6f4a65d0d77beeb98968f9b1576 Mon Sep 17 00:00:00 2001 From: Olivier Date: Mon, 18 May 2026 18:05:06 +0200 Subject: [PATCH] fix: return 400 on duplicate vlan_id in update_vlan update_vlan now checks for vlan_id conflicts (excluding the current record) before committing, matching the behaviour of create_vlan and preventing an unhandled IntegrityError 500. Co-Authored-By: Claude Sonnet 4.6 --- backend/routers/vlans.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/routers/vlans.py b/backend/routers/vlans.py index 6edf041..6a10715 100644 --- a/backend/routers/vlans.py +++ b/backend/routers/vlans.py @@ -85,6 +85,14 @@ def update_vlan(vlan_pk: int, vlan: VlanCreate, db: Session = Depends(get_db)): db_vlan = db.query(models.Vlan).filter(models.Vlan.id == vlan_pk).first() if not db_vlan: raise HTTPException(status_code=404, detail="VLAN introuvable") + if vlan.vlan_id is not None: + conflict = ( + db.query(models.Vlan) + .filter(models.Vlan.vlan_id == vlan.vlan_id, models.Vlan.id != vlan_pk) + .first() + ) + if conflict: + raise HTTPException(status_code=400, detail=f"VLAN {vlan.vlan_id} existe déjà") for k, v in vlan.model_dump().items(): setattr(db_vlan, k, v) db.commit()