Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions django_mongodb_backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def get_database_version(self):
@async_unsafe
def start_transaction_mongo(self):
if self.session is None:
self.ensure_connection()
self.session = self.connection.start_session()
with debug_transaction(self, "session.start_transaction()"):
self.session.start_transaction()
Expand Down
2 changes: 2 additions & 0 deletions docs/releases/5.2.x.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Bug fixes
:attr:`~django.db.models.Field.db_column`.
- Corrected the search index type of ``EmbeddedModelField`` and
``PolymorphicEmbeddedModelField`` from ``embeddedDocuments`` to ``document``.
- Fixed ``transaction.atomic()`` crash if the database connection isn't
initialized.

Deprecated features
-------------------
Expand Down
8 changes: 7 additions & 1 deletion tests/transactions_/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db import DatabaseError
from django.db import DatabaseError, connection
from django.test import TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature

from django_mongodb_backend import transaction
Expand Down Expand Up @@ -140,6 +140,12 @@ def __call__(self):

transaction.atomic(Callable()) # Must not raise an exception

def test_initializes_connection(self):
"""transaction.atomic() opens the connection if needed."""
connection.close_pool()
with transaction.atomic():
pass


@skipIfDBFeature("_supports_transactions")
class AtomicNotSupportedTests(TransactionTestCase):
Expand Down
Loading