diff --git a/app/routers/planning_import.py b/app/routers/planning_import.py index 7c438a2..9057827 100644 --- a/app/routers/planning_import.py +++ b/app/routers/planning_import.py @@ -490,13 +490,15 @@ async def import_upload(request: Request, db=Depends(get_db), year_match = re.search(r"(20\d{2})", fname) year = int(year_match.group(1)) if year_match else None - # Insert header - db.execute(text(""" + # Insert header (RETURNING id : evite le bug lastval() pollué par triggers) + import_id = db.execute(text(""" INSERT INTO patch_planning_imports (filename, year, sheet_count, row_count, uploaded_by, note) VALUES (:fn, :y, 0, 0, :uid, :nt) - """), {"fn": fname, "y": year, "uid": user.get("uid"), "nt": note or None}) + RETURNING id + """), {"fn": fname, "y": year, "uid": user.get("uid"), "nt": note or None}).scalar() db.commit() - import_id = db.execute(text("SELECT lastval()")).scalar() + if not import_id: + return RedirectResponse(url="/patching/import?err=insert_header", status_code=303) sheet_count = 0 row_count = 0