File tree Expand file tree Collapse file tree 3 files changed +9
-2
lines changed Expand file tree Collapse file tree 3 files changed +9
-2
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 @@ -15,7 +15,7 @@ New features
1515Bug fixes
1616---------
1717
18- - .. .
18+ - Fixed `` transaction.atomic() `` crash if the connection isn't initialized .
1919
2020Deprecated features
2121-------------------
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