summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Morgan <andrewm@element.io>2022-08-08 12:13:17 +0100
committerAndrew Morgan <andrewm@element.io>2022-08-08 12:13:17 +0100
commit90128dd3557cfacbcc000fcdc5cc61179fb3ef4b (patch)
treeb385e03bfdec53068e19ef49ecc3b725f6ec00f9
parentDo not return the number of deleted rows from simple_truncate (diff)
downloadsynapse-90128dd3557cfacbcc000fcdc5cc61179fb3ef4b.tar.xz
Raise a ValueError if keyvalues is falsely
-rw-r--r--synapse/storage/database.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/synapse/storage/database.py b/synapse/storage/database.py
index 9cce458dfc..70b5601a12 100644
--- a/synapse/storage/database.py
+++ b/synapse/storage/database.py
@@ -2108,18 +2108,25 @@ class DatabasePool:
     ) -> int:
         """Executes a DELETE query on the named table.
 
-        Filters rows by the key-value pairs.
+        Filter rows by the key-value pairs.
 
         Args:
             table: string giving the table name
-            keyvalues: dict of column names and values to select the row with. If empty,
-                no rows will be deleted.
+            keyvalues: dict of column names and values to select the row with. Must
+                not be empty.
 
         Returns:
             The number of deleted rows.
+
+        Raises:
+            ValueError: if keyvalues was a falsey value, such as an empty dict.
         """
         if not keyvalues:
-            return 0
+            raise ValueError(
+                "'keyvalues' arg to simple_delete_txn was falsey. If you were trying to "
+                "delete all rows from a database, perhaps try "
+                "DatabasePool.simple_truncate instead?"
+            )
 
         sql = "DELETE FROM %s WHERE %s" % (
             table,