diff --git a/django/db/backends/ado_mssql/base.py b/django/db/backends/ado_mssql/base.py index 25832e25df..8d813c6704 100644 --- a/django/db/backends/ado_mssql/base.py +++ b/django/db/backends/ado_mssql/base.py @@ -70,7 +70,8 @@ class DatabaseWrapper(object): return cursor def _commit(self): - return self.connection.commit() + if self.connection: + return self.connection.commit() def _rollback(self): if self.connection: diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index b760f47786..6040b9c5f3 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -91,7 +91,8 @@ class DatabaseWrapper(object): return cursor def _commit(self): - self.connection.commit() + if self.connection: + self.connection.commit() def _rollback(self): if self.connection: diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index a9a0662c15..754fcef776 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -36,7 +36,8 @@ class DatabaseWrapper(object): return FormatStylePlaceholderCursor(self.connection) def _commit(self): - self.connection.commit() + if self.connection: + self.connection.commit() def _rollback(self): if self.connection: diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py index 774b52a1d6..cc6686ed81 100644 --- a/django/db/backends/postgresql/base.py +++ b/django/db/backends/postgresql/base.py @@ -43,7 +43,8 @@ class DatabaseWrapper(object): return cursor def _commit(self): - return self.connection.commit() + if self.connection: + return self.connection.commit() def _rollback(self): if self.connection: diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index 65f3e698ae..d62376596f 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -44,7 +44,8 @@ class DatabaseWrapper(object): return cursor def _commit(self): - return self.connection.commit() + if self.connection: + return self.connection.commit() def _rollback(self): if self.connection: diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index e6aff2d847..2d42700e63 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -56,7 +56,8 @@ class DatabaseWrapper(local): return cursor def _commit(self): - self.connection.commit() + if self.connection: + self.connection.commit() def _rollback(self): if self.connection: