changeset 2918:21cf8395616c

memory (sqlite): fixed fileUpdate when original value is not set (NULL)
author Goffi <goffi@goffi.org>
date Fri, 26 Apr 2019 11:57:26 +0200
parents adf6e33a3e50
children e4715a609d75
files sat/memory/sqlite.py
diffstat 1 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/sat/memory/sqlite.py	Fri Apr 26 11:57:26 2019 +0200
+++ b/sat/memory/sqlite.py	Fri Apr 26 11:57:26 2019 +0200
@@ -905,11 +905,18 @@
                 older_value_raw = cursor.fetchone()[0]
             except TypeError:
                 raise exceptions.NotFound
-            value = json.loads(older_value_raw)
+            if older_value_raw is None:
+                value = {}
+            else:
+                value = json.loads(older_value_raw)
             update_cb(value)
             value_raw = json.dumps(value)
-            update_query = 'UPDATE files SET {column}=? WHERE id=? AND {column}=?'.format(column=column)
-            update_args = (value_raw, file_id, older_value_raw)
+            if older_value_raw is None:
+                update_query = 'UPDATE files SET {column}=? WHERE id=? AND {column} is NULL'.format(column=column)
+                update_args = (value_raw, file_id)
+            else:
+                update_query = 'UPDATE files SET {column}=? WHERE id=? AND {column}=?'.format(column=column)
+                update_args = (value_raw, file_id, older_value_raw)
             try:
                 cursor.execute(update_query, update_args)
             except sqlite3.Error: