From 423c0d5e293bf6bd5f859430126269c31313585a Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Thu, 7 Mar 2013 14:47:50 +0100 Subject: [PATCH] Added a safety net for developers messing with autocommit. --- django/db/backends/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 2d1de9509e..cb17e1db61 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -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