summary refs log tree commit diff
diff options
context:
space:
mode:
authorSatsuki Yanagi <17376330+u1-liquid@users.noreply.github.com>2020-01-17 23:30:35 +0900
committerErik Johnston <erik@matrix.org>2020-01-17 14:30:35 +0000
commit722b4f302d705f497355f206ecb160de1bef2074 (patch)
tree33dc72ad6c6698e57ce0b7899930f67c5b52022d
parentMerge pull request #6714 from matrix-org/babolivier/retention_select_event (diff)
downloadsynapse-722b4f302d705f497355f206ecb160de1bef2074.tar.xz
Fix syntax error in run_upgrade for schema 57 (#6728)
Fix #6727
Related #6655

Co-authored-by: Erik Johnston <erikj@jki.re>
-rw-r--r--changelog.d/6728.bugfix1
-rw-r--r--synapse/storage/data_stores/main/schema/delta/57/local_current_membership.py7
2 files changed, 5 insertions, 3 deletions
diff --git a/changelog.d/6728.bugfix b/changelog.d/6728.bugfix
new file mode 100644
index 0000000000..5a136e17be
--- /dev/null
+++ b/changelog.d/6728.bugfix
@@ -0,0 +1 @@
+Fix a bug causing `ValueError: unsupported format character ''' (0x27) at index 312` error when running the schema 57 upgrade script.
diff --git a/synapse/storage/data_stores/main/schema/delta/57/local_current_membership.py b/synapse/storage/data_stores/main/schema/delta/57/local_current_membership.py
index 601c236c4a..63b5acdcf7 100644
--- a/synapse/storage/data_stores/main/schema/delta/57/local_current_membership.py
+++ b/synapse/storage/data_stores/main/schema/delta/57/local_current_membership.py
@@ -56,7 +56,7 @@ def run_upgrade(cur, database_engine, config, *args, **kwargs):
             INSERT INTO local_current_membership (room_id, user_id, event_id, membership)
                 SELECT c.room_id, state_key AS user_id, event_id, c.membership
                 FROM current_state_events AS c
-                WHERE type = 'm.room.member' AND c.membership IS NOT NULL AND state_key like '%' || ?
+                WHERE type = 'm.room.member' AND c.membership IS NOT NULL AND state_key LIKE ?
         """
     else:
         # We can't rely on the membership column, so we need to join against
@@ -66,9 +66,10 @@ def run_upgrade(cur, database_engine, config, *args, **kwargs):
                 SELECT c.room_id, state_key AS user_id, event_id, r.membership
                 FROM current_state_events AS c
                 INNER JOIN room_memberships AS r USING (event_id)
-                WHERE type = 'm.room.member' and state_key like '%' || ?
+                WHERE type = 'm.room.member' AND state_key LIKE ?
         """
-    cur.execute(sql, (config.server_name,))
+    sql = database_engine.convert_param_style(sql)
+    cur.execute(sql, ("%:" + config.server_name,))
 
     cur.execute(
         "CREATE UNIQUE INDEX local_current_membership_idx ON local_current_membership(user_id, room_id)"