Added a safety net for developers messing with autocommit.

This commit is contained in:
Aymeric Augustin 2013-03-07 14:47:50 +01:00
parent 107d9b1d97
commit 423c0d5e29
1 changed files with 7 additions and 0 deletions

View File

@ -417,12 +417,19 @@ class BaseDatabaseWrapper(object):
or if it outlived its maximum age.
"""
if self.connection is not None:
# If the application didn't restore the original autocommit setting,
# don't take chances, drop the connection.
if self.autocommit != self.settings_dict['AUTOCOMMIT']:
self.close()
return
if self.errors_occurred:
if self.is_usable():
self.errors_occurred = False
else:
self.close()
return
if self.close_at is not None and time.time() >= self.close_at:
self.close()
return