memory (sqlite): fixed fileUpdate when original value is not set (NULL)

This commit is contained in:
Goffi 2019-04-26 11:57:26 +02:00
commit 621c6b3ffa

View file

@ -905,11 +905,18 @@ class SqliteStorage(object):
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: