summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-03-04 14:03:21 +0000
committerErik Johnston <erik@matrix.org>2015-03-04 14:03:41 +0000
commit16dd87d848f686835cbff82333e00c6411b1436b (patch)
tree7b481bae44550d834094640f9d22ccea455714f3
parentAdd unique constraint on schema_version.lock schema. Use conflict clause in sql. (diff)
downloadsynapse-16dd87d848f686835cbff82333e00c6411b1436b.tar.xz
Don't assume db conn is a Context Manager.
Twisted adbapi wrapped connections aren't context managers.
-rw-r--r--synapse/storage/__init__.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py
index c09228c37f..87189e54b8 100644
--- a/synapse/storage/__init__.py
+++ b/synapse/storage/__init__.py
@@ -583,7 +583,7 @@ def prepare_database(db_conn):
     """Prepares a database for usage. Will either create all necessary tables
     or upgrade from an older schema version.
     """
-    with db_conn:
+    try:
         cur = db_conn.cursor()
         version_info = _get_or_create_schema_state(cur)
 
@@ -596,6 +596,10 @@ def prepare_database(db_conn):
         cur.execute("PRAGMA user_version = %d" % (SCHEMA_VERSION,))
 
         cur.close()
+        db_conn.commit()
+    except:
+        db_conn.rollback()
+        raise
 
 
 def _setup_new_database(cur):