File tree Expand file tree Collapse file tree 3 files changed +10
-1
lines changed Expand file tree Collapse file tree 3 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -272,6 +272,7 @@ def get_database_version(self):
272272 @async_unsafe
273273 def start_transaction_mongo (self ):
274274 if self .session is None :
275+ self .ensure_connection ()
275276 self .session = self .connection .start_session ()
276277 with debug_transaction (self , "session.start_transaction()" ):
277278 self .session .start_transaction ()
Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ Bug fixes
2323 :attr: `~django.db.models.Field.db_column `.
2424- Corrected the search index type of ``EmbeddedModelField `` and
2525 ``PolymorphicEmbeddedModelField `` from ``embeddedDocuments `` to ``document ``.
26+ - Fixed ``transaction.atomic() `` crash if the database connection isn't
27+ initialized.
2628
2729Deprecated features
2830-------------------
Original file line number Diff line number Diff line change 1- from django .db import DatabaseError
1+ from django .db import DatabaseError , connection
22from django .test import TransactionTestCase , skipIfDBFeature , skipUnlessDBFeature
33
44from django_mongodb_backend import transaction
@@ -140,6 +140,12 @@ def __call__(self):
140140
141141 transaction .atomic (Callable ()) # Must not raise an exception
142142
143+ def test_initializes_connection (self ):
144+ """transaction.atomic() opens the connection if needed."""
145+ connection .close_pool ()
146+ with transaction .atomic ():
147+ pass
148+
143149
144150@skipIfDBFeature ("_supports_transactions" )
145151class AtomicNotSupportedTests (TransactionTestCase ):
You can’t perform that action at this time.
0 commit comments