Commit 423c0d5e authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

Added a safety net for developers messing with autocommit.

parent 107d9b1d
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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