summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorAmber Brown <hawkowl@atleastfornow.net>2019-01-09 22:26:25 +1100
committerGitHub <noreply@github.com>2019-01-09 22:26:25 +1100
commit7960c26fda8dd8d2d1333b45ef4f5c644930a619 (patch)
treed09679aa5c1e399964811f5f8e5edf54bc15818a /synapse/storage
parentMerge pull request #4362 from matrix-org/erikj/better_errors (diff)
downloadsynapse-7960c26fda8dd8d2d1333b45ef4f5c644930a619.tar.xz
Fix adding new rows instead of updating them if one of the key values is a NULL in upserts. (#4369)
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/_base.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index 1d3069b143..865b5e915a 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -547,11 +547,19 @@ class SQLBaseStore(object):
         if lock:
             self.database_engine.lock_table(txn, table)
 
+        def _getwhere(key):
+            # If the value we're passing in is None (aka NULL), we need to use
+            # IS, not =, as NULL = NULL equals NULL (False).
+            if keyvalues[key] is None:
+                return "%s IS ?" % (key,)
+            else:
+                return "%s = ?" % (key,)
+
         # First try to update.
         sql = "UPDATE %s SET %s WHERE %s" % (
             table,
             ", ".join("%s = ?" % (k,) for k in values),
-            " AND ".join("%s = ?" % (k,) for k in keyvalues)
+            " AND ".join(_getwhere(k) for k in keyvalues)
         )
         sqlargs = list(values.values()) + list(keyvalues.values())