summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-05-18 11:48:46 +0200
committerAndrew Godwin <andrew@aeracode.org>2013-05-18 11:48:46 +0200
commit331546f6ee7f50a92c01f919e1bb4bea6ed32625 (patch)
tree070e1a2e8a2e63ccd12666233dd881b9415a751e /django
parentce5bd42259bc95d372ab0d65dbae793e6251ea80 (diff)
More conversion to a ContextManager schema_editor
Diffstat (limited to 'django')
-rw-r--r--django/db/backends/schema.py33
-rw-r--r--django/db/migrations/state.py6
2 files changed, 13 insertions, 26 deletions
diff --git a/django/db/backends/schema.py b/django/db/backends/schema.py
index 78ea80022f..d282e0898b 100644
--- a/django/db/backends/schema.py
+++ b/django/db/backends/schema.py
@@ -61,38 +61,19 @@ class BaseDatabaseSchemaEditor(object):
# State-managing methods
- def start(self):
- """
- Marks the start of a schema-altering run.
- """
- self.deferred_sql = []
- atomic(self.connection.alias).__enter__()
-
- def commit(self):
- """
- Finishes a schema-altering run.
- """
- for sql in self.deferred_sql:
- self.execute(sql)
- atomic(self.connection.alias).__exit__(None, None, None)
-
- def rollback(self):
- """
- Tries to roll back a schema-altering run. Call instead of commit().
- """
- if not self.connection.features.can_rollback_ddl:
- raise RuntimeError("Cannot rollback schema changes on this backend")
- atomic(self.connection.alias).__exit__(*sys.exc_info())
-
def __enter__(self):
- self.start()
+ self.deferred_sql = []
+ atomic(self.connection.alias, self.connection.features.can_rollback_ddl).__enter__()
return self
def __exit__(self, exc_type, exc_value, traceback):
if exc_type is None:
- self.commit()
+ for sql in self.deferred_sql:
+ self.execute(sql)
+ atomic(self.connection.alias, self.connection.features.can_rollback_ddl).__exit__(None, None, None)
else:
- self.rollback()
+ # Continue propagating exception
+ return None
# Core utility functions
diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py
index 3dbbbe27f8..9678026c79 100644
--- a/django/db/migrations/state.py
+++ b/django/db/migrations/state.py
@@ -30,6 +30,12 @@ class ProjectState(object):
model.render(self.app_cache)
return self.app_cache
+ @classmethod
+ def from_app_cache(cls, app_cache):
+ "Takes in an AppCache and returns a ProjectState matching it"
+ for model in app_cache.get_models():
+ print model
+
class ModelState(object):
"""