From 63c321d017e5ba77ee5a39f9ed55051c4f7b9126 Mon Sep 17 00:00:00 2001 From: Gabriele Battimelli Date: Wed, 8 Jul 2026 02:16:16 +0200 Subject: [PATCH] Make topological_sort's level-0 seed insert idempotent The full pipeline finally ran end-to-end through analysis, module, symbol, and declaration loads (~50 min), reaching topological_sort -- which crashed: psycopg.errors.UniqueViolation: duplicate key value violates unique constraint "level_pkey" Every other INSERT in this file (load_module, load_symbol, both dependency inserts, load_declaration) uses ON CONFLICT DO NOTHING so re-runs against a DB with prior data are safe. The iterative level insert already guards against this via 'WHERE NOT EXISTS (SELECT 1 FROM level l ...)', but the level-0 seed insert had no such guard, so it collided on symbols that already had a level from an earlier successful run. Add ON CONFLICT DO NOTHING to match. --- database/jixia_db.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/database/jixia_db.py b/database/jixia_db.py index dca48c3..c4f11c2 100644 --- a/database/jixia_db.py +++ b/database/jixia_db.py @@ -180,6 +180,7 @@ def topological_sort(): SELECT name, 0 FROM symbol v WHERE NOT EXISTS (SELECT 1 FROM dependency e WHERE e.source = v.name) + ON CONFLICT DO NOTHING """) while cursor.rowcount: logger.info("topological sort: %d rows affected", cursor.rowcount) @@ -193,6 +194,7 @@ def topological_sort(): GROUP BY e.source HAVING EVERY(l.level IS NOT NULL) = TRUE + ON CONFLICT DO NOTHING """) with conn.cursor() as cursor: