From 1a988385808a5a324d3a63b4271a654964a4a72a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9lestin=20Matte?= <gitlab@cmatte.me>
Date: Mon, 1 Nov 2021 21:18:51 +0100
Subject: [PATCH] Bugfix: missing ids in pglister_sync

groupid and listid are not explicitly set in pglister_sync's queries, which
causes the script to fail as these fields are NOT NULL and postgresql default
configuration does not auto-fill id fields.
This patch sets them explicitly by reusing the ones obtained from pglister.
---
 loader/pglister_sync.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/loader/pglister_sync.py b/loader/pglister_sync.py
index f95d369..a5ca645 100755
--- a/loader/pglister_sync.py
+++ b/loader/pglister_sync.py
@@ -49,7 +49,8 @@ if __name__ == "__main__":
             'group': name,
         })
         if not curs.fetchone()[0]:
-            curs.execute("INSERT INTO listgroups (groupname, sortkey) VALUES (%(group)s, 100) RETURNING groupname", {
+            curs.execute("INSERT INTO listgroups (groupid, groupname, sortkey) VALUES (%(groupid)s, %(group)s, 100) RETURNING groupname", {
+                'groupid': id,
                 'group': name,
             })
             print("Added group %s" % name)
@@ -60,7 +61,8 @@ if __name__ == "__main__":
             'name': l['listname'],
         })
         if curs.rowcount == 0:
-            curs.execute("INSERT INTO lists (listname, shortdesc, description, active, groupid) SELECT %(name)s, %(name)s, %(desc)s, 't', groupid FROM listgroups WHERE groupname=%(groupname)s RETURNING listid, listname", {
+            curs.execute("INSERT INTO lists (listid, listname, shortdesc, description, active, groupid) SELECT %(listid)s, %(name)s, %(name)s, %(desc)s, 't', groupid, FROM listgroups WHERE groupname=%(groupname)s RETURNING listid, listname", {
+                'listid': l['listid'],
                 'name': l['listname'],
                 'desc': l['longdesc'],
                 'groupname': l['group']['groupname'],
-- 
2.34.1

