diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 7c918e0609..4dab0e3e16 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -188,6 +188,8 @@ class BaseDatabaseWrapper(object): # Don't call validate_no_atomic_block() to avoid making it difficult # to get rid of a connection in an invalid state. The next connect() # will reset the transaction state anyway. + if self.closed_in_transaction or self.connection is None: + return try: self._close() finally: