Browse Source

Avoid updating the same rows multiple times with simple_update_many_txn. (#16609)

simple_update_many_txn had a bug in it which would cause each
update to be applied twice.
tags/v1.97.0rc1
Patrick Cloke 6 months ago
committed by GitHub
parent
commit
455ef04187
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 6 deletions
  1. +1
    -0
      changelog.d/16609.bugfix
  2. +1
    -4
      synapse/storage/database.py
  3. +2
    -2
      tests/storage/test_base.py

+ 1
- 0
changelog.d/16609.bugfix View File

@@ -0,0 +1 @@
Fix a long-standing bug where some queries updated the same row twice. Introduced in Synapse 1.57.0.

+ 1
- 4
synapse/storage/database.py View File

@@ -2060,10 +2060,7 @@ class DatabasePool:

# List of tuples of (value values, then key values)
# (This matches the order needed for the query)
args = [tuple(x) + tuple(y) for x, y in zip(value_values, key_values)]

for ks, vs in zip(key_values, value_values):
args.append(tuple(vs) + tuple(ks))
args = [tuple(vv) + tuple(kv) for vv, kv in zip(value_values, key_values)]

# 'col1 = ?, col2 = ?, ...'
set_clause = ", ".join(f"{n} = ?" for n in value_names)


+ 2
- 2
tests/storage/test_base.py View File

@@ -363,12 +363,12 @@ class SQLBaseStoreTestCase(unittest.TestCase):
self.mock_execute_batch.assert_called_once_with(
self.mock_txn,
"UPDATE tablename SET col3 = ? WHERE col1 = ? AND col2 = ?",
[("val3", "val1", "val2"), ("val3", "val1", "val2")],
[("val3", "val1", "val2")],
)
else:
self.mock_txn.executemany.assert_called_once_with(
"UPDATE tablename SET col3 = ? WHERE col1 = ? AND col2 = ?",
[("val3", "val1", "val2"), ("val3", "val1", "val2")],
[("val3", "val1", "val2")],
)

# key_values and value_values must be the same length.


Loading…
Cancel
Save