changeset 402:724e39d596a9

psql: use a set for categories, to avoid duplicates (and constraint failure)
author Goffi <goffi@goffi.org>
date Thu, 23 May 2019 08:58:29 +0200
parents 907b10480394
children 1dc606612405
files src/pgsql_storage.py
diffstat 1 files changed, 2 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/pgsql_storage.py	Tue May 07 09:15:20 2019 +0200
+++ b/src/pgsql_storage.py	Thu May 23 08:58:29 2019 +0200
@@ -958,7 +958,8 @@
             cursor.execute("""DELETE FROM item_categories
                               WHERE item_id=%s""", (item_id,))
 
-        for category in categories:
+        # we use a set to avoid duplicates
+        for category in set(categories):
             cursor.execute("""INSERT INTO item_categories (item_id, category)
                               VALUES (%s, %s)""", (item_id, category))