diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-03-13 14:54:44 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-03-13 15:17:40 +0100 |
| commit | 93af822c001b393299b4c5dc58abcd98f6e1e2e8 (patch) | |
| tree | 1fc4d7ccd9eb61549008ab5372adf9a537bb0e9c | |
| parent | 83a416f5e764705ed553f3513bdf9587270554c6 (diff) | |
Improved recovery when the connection is closed in an atomic block.
| -rw-r--r-- | django/db/backends/__init__.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 27b39a3d1f..b713b4c97a 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -52,14 +52,14 @@ class BaseDatabaseWrapper(object): self._dirty = False # Tracks if the connection is in a transaction managed by 'atomic'. self.in_atomic_block = False + # List of savepoints created by 'atomic' + self.savepoint_ids = [] # Tracks if the outermost 'atomic' block should commit on exit, # ie. if autocommit was active on entry. self.commit_on_exit = True # Tracks if the transaction should be rolled back to the next # available savepoint because of an exception in an inner block. self.needs_rollback = False - # List of savepoints created by 'atomic' - self.savepoint_ids = [] # Connection termination related attributes self.close_at = None @@ -100,6 +100,9 @@ class BaseDatabaseWrapper(object): def connect(self): """Connects to the database. Assumes that the connection is closed.""" + # In case the previous connection was closed while in an atomic block + self.in_atomic_block = False + self.savepoint_ids = [] # Reset parameters defining when to close the connection max_age = self.settings_dict['CONN_MAX_AGE'] self.close_at = None if max_age is None else time.time() + max_age @@ -179,6 +182,9 @@ class BaseDatabaseWrapper(object): Closes the connection to the database. """ self.validate_thread_sharing() + # Don't call validate_no_atomic_block() to avoid making it difficult + # to get rid of a connection in an invalid state. The next connect() + # will reset the transaction state anyway. try: self._close() finally: |
