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 @@ -21,6 +21,8 @@ Bug fixes
2121 ``EmbeddedModel ``).
2222- Made ``EmbeddedModel `` fields respect
2323 :attr: `~django.db.models.Field.db_column `.
24+ - Fixed ``transaction.atomic() `` crash if the database connection isn't
25+ initialized.
2426
2527Deprecated features
2628-------------------
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