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):
272
272
@async_unsafe
273
273
def start_transaction_mongo (self ):
274
274
if self .session is None :
275
+ self .ensure_connection ()
275
276
self .session = self .connection .start_session ()
276
277
with debug_transaction (self , "session.start_transaction()" ):
277
278
self .session .start_transaction ()
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ New features
15
15
Bug fixes
16
16
---------
17
17
18
- - .. .
18
+ - Fixed `` transaction.atomic() `` crash if the connection isn't initialized .
19
19
20
20
Deprecated features
21
21
-------------------
Original file line number Diff line number Diff line change 1
- from django .db import DatabaseError
1
+ from django .db import DatabaseError , connection
2
2
from django .test import TransactionTestCase , skipIfDBFeature , skipUnlessDBFeature
3
3
4
4
from django_mongodb_backend import transaction
@@ -140,6 +140,12 @@ def __call__(self):
140
140
141
141
transaction .atomic (Callable ()) # Must not raise an exception
142
142
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
+
143
149
144
150
@skipIfDBFeature ("_supports_transactions" )
145
151
class AtomicNotSupportedTests (TransactionTestCase ):
You can’t perform that action at this time.
0 commit comments