From 3becac84845cee8f12a5fb7f68c87cbaf029c6a0 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 23 Mar 2014 23:09:26 +0100 Subject: [PATCH] Fixed #22321 -- Wrapped exceptions in _set_autocommit. Refs #21202. --- django/db/backends/mysql/base.py | 3 ++- django/db/backends/oracle/base.py | 3 ++- django/db/backends/postgresql_psycopg2/base.py | 15 ++++++++------- django/db/backends/sqlite3/base.py | 3 ++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index cbe37fc84c..85bcd8f79b 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -488,7 +488,8 @@ class DatabaseWrapper(BaseDatabaseWrapper): pass def _set_autocommit(self, autocommit): - self.connection.autocommit(autocommit) + with self.wrap_database_errors: + self.connection.autocommit(autocommit) def disable_constraint_checking(self): """ diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index da0fdb121f..01f4960470 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -687,7 +687,8 @@ class DatabaseWrapper(BaseDatabaseWrapper): pass def _set_autocommit(self, autocommit): - self.connection.autocommit = autocommit + with self.wrap_database_errors: + self.connection.autocommit = autocommit def check_constraints(self, table_names=None): """ diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index 47bcf2f41a..68cc5b121e 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -189,14 +189,15 @@ class DatabaseWrapper(BaseDatabaseWrapper): self.connection.set_isolation_level(isolation_level) def _set_autocommit(self, autocommit): - if self.psycopg2_version >= (2, 4, 2): - self.connection.autocommit = autocommit - else: - if autocommit: - level = psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT + with self.wrap_database_errors: + if self.psycopg2_version >= (2, 4, 2): + self.connection.autocommit = autocommit else: - level = self.isolation_level - self.connection.set_isolation_level(level) + if autocommit: + level = psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT + else: + level = self.isolation_level + self.connection.set_isolation_level(level) def check_constraints(self, table_names=None): """ diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index 9709e8449f..d594b89ef8 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -411,7 +411,8 @@ class DatabaseWrapper(BaseDatabaseWrapper): level = '' # 'isolation_level' is a misleading API. # SQLite always runs at the SERIALIZABLE isolation level. - self.connection.isolation_level = level + with self.wrap_database_errors: + self.connection.isolation_level = level def check_constraints(self, table_names=None): """