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):
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 @@ -23,6 +23,8 @@ Bug fixes
23
23
:attr: `~django.db.models.Field.db_column `.
24
24
- Corrected the search index type of ``EmbeddedModelField `` and
25
25
``PolymorphicEmbeddedModelField `` from ``embeddedDocuments `` to ``document ``.
26
+ - Fixed ``transaction.atomic() `` crash if the database connection isn't
27
+ initialized.
26
28
27
29
Deprecated features
28
30
-------------------
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