summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-04-19 09:01:45 +0100
committerAndrew Godwin <andrew@aeracode.org>2013-04-19 09:01:45 +0100
commit6e21a59402e1a90c16113e1fac8e4ff39b6914d3 (patch)
treef635e3b78dec6c7658e4ff8bb579639fcba6bf9a
parent7f3678dc4cd7146c49bac3fb8f5211f647636aa3 (diff)
Fix schema editor interaction with new transactions
-rw-r--r--django/db/backends/schema.py8
-rw-r--r--tests/schema/tests.py2
2 files changed, 6 insertions, 4 deletions
diff --git a/django/db/backends/schema.py b/django/db/backends/schema.py
index 5e4eb6bf17..e4a923f2be 100644
--- a/django/db/backends/schema.py
+++ b/django/db/backends/schema.py
@@ -64,7 +64,9 @@ class BaseDatabaseSchemaEditor(object):
Marks the start of a schema-altering run.
"""
self.deferred_sql = []
- self.connection.set_autocommit(False)
+ self.old_autocommit = self.connection.autocommit
+ if self.connection.autocommit:
+ self.connection.set_autocommit(False)
def commit(self):
"""
@@ -73,7 +75,7 @@ class BaseDatabaseSchemaEditor(object):
for sql in self.deferred_sql:
self.execute(sql)
self.connection.commit()
- self.connection.set_autocommit(True)
+ self.connection.set_autocommit(self.old_autocommit)
def rollback(self):
"""
@@ -82,7 +84,7 @@ class BaseDatabaseSchemaEditor(object):
if not self.connection.features.can_rollback_ddl:
raise RuntimeError("Cannot rollback schema changes on this backend")
self.connection.rollback()
- self.connection.set_autocommit(True)
+ self.connection.set_autocommit(self.old_autocommit)
# Core utility functions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 72c0c07af5..bd4ae0db34 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -453,7 +453,7 @@ class SchemaTests(TransactionTestCase):
Tag.objects.create(title="foo", slug="foo")
Tag.objects.create(title="bar", slug="foo")
connection.rollback()
- # Alter the slug field to be non-unique
+ # Alter the slug field to be unique
new_new_field = SlugField(unique=True)
new_new_field.set_attributes_from_name("slug")
editor = connection.schema_editor()