Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 455ef04

Browse files
authored
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.
1 parent 9738b1c commit 455ef04

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

changelog.d/16609.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a long-standing bug where some queries updated the same row twice. Introduced in Synapse 1.57.0.

synapse/storage/database.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,10 +2060,7 @@ def simple_update_many_txn(
20602060

20612061
# List of tuples of (value values, then key values)
20622062
# (This matches the order needed for the query)
2063-
args = [tuple(x) + tuple(y) for x, y in zip(value_values, key_values)]
2064-
2065-
for ks, vs in zip(key_values, value_values):
2066-
args.append(tuple(vs) + tuple(ks))
2063+
args = [tuple(vv) + tuple(kv) for vv, kv in zip(value_values, key_values)]
20672064

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

tests/storage/test_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,12 @@ def test_update_many(self) -> Generator["defer.Deferred[object]", object, None]:
363363
self.mock_execute_batch.assert_called_once_with(
364364
self.mock_txn,
365365
"UPDATE tablename SET col3 = ? WHERE col1 = ? AND col2 = ?",
366-
[("val3", "val1", "val2"), ("val3", "val1", "val2")],
366+
[("val3", "val1", "val2")],
367367
)
368368
else:
369369
self.mock_txn.executemany.assert_called_once_with(
370370
"UPDATE tablename SET col3 = ? WHERE col1 = ? AND col2 = ?",
371-
[("val3", "val1", "val2"), ("val3", "val1", "val2")],
371+
[("val3", "val1", "val2")],
372372
)
373373

374374
# key_values and value_values must be the same length.

0 commit comments

Comments
 (0)