Skip to content

Commit f6cb920

Browse files
committed
add validation of broken transactions
1 parent 44bfab1 commit f6cb920

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

django_mongodb_backend/compiler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ def execute_sql(self, returning_fields=None):
685685
@wrap_database_errors
686686
def insert(self, docs, returning_fields=None):
687687
"""Store a list of documents using field columns as element names."""
688+
self.connection.validate_no_broken_transaction()
688689
inserted_ids = self.collection.insert_many(
689690
docs, session=self.connection.session
690691
).inserted_ids
@@ -770,6 +771,7 @@ def execute_sql(self, result_type):
770771

771772
@wrap_database_errors
772773
def update(self, criteria, pipeline):
774+
self.connection.validate_no_broken_transaction()
773775
return self.collection.update_many(
774776
criteria, pipeline, session=self.connection.session
775777
).matched_count

django_mongodb_backend/features.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
8484
# Value.as_mql() doesn't call output_field.get_db_prep_save():
8585
# https://github.com/mongodb/django-mongodb-backend/issues/282
8686
"model_fields.test_jsonfield.TestSaveLoad.test_bulk_update_custom_get_prep_value",
87-
# to debug
88-
"transactions.tests.AtomicMiscTests.test_mark_for_rollback_on_error_in_transaction",
8987
}
9088
# $bitAnd, #bitOr, and $bitXor are new in MongoDB 6.3.
9189
_django_test_expected_failures_bitwise = {

django_mongodb_backend/query.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def __repr__(self):
6161
@wrap_database_errors
6262
def delete(self):
6363
"""Execute a delete query."""
64+
self.compiler.connection.validate_no_broken_transaction()
6465
if self.compiler.subqueries:
6566
raise NotSupportedError("Cannot use QuerySet.delete() when a subquery is required.")
6667
return self.compiler.collection.delete_many(
@@ -73,6 +74,7 @@ def get_cursor(self):
7374
Return a pymongo CommandCursor that can be iterated on to give the
7475
results of the query.
7576
"""
77+
self.compiler.connection.validate_no_broken_transaction()
7678
return self.compiler.collection.aggregate(
7779
self.get_pipeline(), session=self.compiler.connection.session
7880
)

0 commit comments

Comments
 (0)