diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index cbe37fc84cc..85bcd8f79b3 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 da0fdb121fd..01f4960470f 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 6ea17cf5435..09b4205bba8 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -192,14 +192,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 9709e8449fa..d594b89ef85 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): """