diff --git a/changelog.d/17815.bugfix b/changelog.d/17815.bugfix
new file mode 100644
index 0000000000000000000000000000000000000000..5dd276709b0be266c5eb1cd9feb5c6b107e29b8c
--- /dev/null
+++ b/changelog.d/17815.bugfix
@@ -0,0 +1 @@
+Avoid lost data on some database query retries.
diff --git a/synapse/storage/databases/state/store.py b/synapse/storage/databases/state/store.py
index aea71b8fcc5aeb367b763bc9ace5e76c1a1c5090..875dba33496c27bf214c64e6a04b1c9289b56762 100644
--- a/synapse/storage/databases/state/store.py
+++ b/synapse/storage/databases/state/store.py
@@ -804,11 +804,11 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore):
         logger.info("[purge] removing redundant state groups")
         txn.execute_batch(
             "DELETE FROM state_groups_state WHERE state_group = ?",
-            ((sg,) for sg in state_groups_to_delete),
+            [(sg,) for sg in state_groups_to_delete],
         )
         txn.execute_batch(
             "DELETE FROM state_groups WHERE id = ?",
-            ((sg,) for sg in state_groups_to_delete),
+            [(sg,) for sg in state_groups_to_delete],
         )
 
     @trace