From b72f1244dd27cfc0c181408518910074186fbd9f Mon Sep 17 00:00:00 2001 From: Admin MPCZ Date: Tue, 14 Apr 2026 13:43:25 +0200 Subject: [PATCH] Use autocommit mode to persist inserts immediately --- tools/import_sanef_assets.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/import_sanef_assets.py b/tools/import_sanef_assets.py index 5baaaa4..378512b 100644 --- a/tools/import_sanef_assets.py +++ b/tools/import_sanef_assets.py @@ -57,7 +57,8 @@ def main(): rows = list(reader) print(f"[INFO] {len(rows)} lignes lues dans le CSV") - with engine.begin() as conn: + conn = engine.connect().execution_options(isolation_level="AUTOCOMMIT") + try: if args.truncate: print("[INFO] Nettoyage des tables référençant servers") if not args.dry_run: @@ -121,7 +122,6 @@ def main(): continue try: - sp = conn.begin_nested() conn.execute(text(""" INSERT INTO servers (hostname, fqdn, domain_ltd, os_family, os_version, machine_type, @@ -130,13 +130,10 @@ def main(): (:hostname, :fqdn, :domain_ltd, :os_family, :os_version, :machine_type, :etat, :site, :vcenter_vm_name, :responsable_nom, :patch_owner_details) """), params) - sp.commit() inserted += 1 if ip: ip_map.append((hostname, ip)) except Exception as e: - try: sp.rollback() - except Exception: pass print(f" [ERR] {hostname}: {str(e)[:200]}") skipped += 1 @@ -153,6 +150,8 @@ def main(): except Exception: pass + finally: + conn.close() print(f"[DONE] Inséré/mis à jour: {inserted} | Ignoré: {skipped}")