mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 11:06:07 -04:00
Fix adding new rows instead of updating them if one of the key values is a NULL in upserts. (#4369)
This commit is contained in:
parent
d1d81d0651
commit
7960c26fda
3 changed files with 81 additions and 1 deletions
|
@ -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())
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue