Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improved recovery when the connection is closed in an atomic block.

  • Loading branch information...
commit 93af822c001b393299b4c5dc58abcd98f6e1e2e8 1 parent 83a416f
@aaugustin aaugustin authored
Showing with 8 additions and 2 deletions.
  1. +8 −2 django/db/backends/__init__.py
View
10 django/db/backends/__init__.py
@@ -52,14 +52,14 @@ def __init__(self, settings_dict, alias=DEFAULT_DB_ALIAS,
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 @@ def create_cursor(self):
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 @@ def close(self):
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:

0 comments on commit 93af822

Please sign in to comment.
Something went wrong with that request. Please try again.