@@ -36,6 +36,10 @@ class DatabaseFeatures(BaseDatabaseFeatures):
36
36
supports_temporal_subtraction = True
37
37
# MongoDB stores datetimes in UTC.
38
38
supports_timezones = False
39
+ # While MongoDB supports transactions in some configurations (see
40
+ # DatabaseFeatures._supports_transactions), django.db.transaction.atomic() is a
41
+ # no-op on this backend.
42
+ supports_transactions = False
39
43
supports_unspecified_pk = True
40
44
uses_savepoints = False
41
45
@@ -92,47 +96,13 @@ class DatabaseFeatures(BaseDatabaseFeatures):
92
96
"expressions.tests.ExpressionOperatorTests.test_lefthand_bitwise_xor_right_null" ,
93
97
"expressions.tests.ExpressionOperatorTests.test_lefthand_transformed_field_bitwise_or" ,
94
98
}
95
- _django_test_expected_failures_no_transactions = {
96
- # "Save with update_fields did not affect any rows." instead of
97
- # "An error occurred in the current transaction. You can't execute
98
- # queries until the end of the 'atomic' block."
99
- "basic.tests.SelectOnSaveTests.test_select_on_save_lying_update" ,
100
- }
101
- _django_test_expected_failures_transactions = {
102
- # When update_or_create() fails with IntegrityError, the transaction
103
- # is no longer usable.
104
- "get_or_create.tests.UpdateOrCreateTests.test_manual_primary_key_test" ,
105
- "get_or_create.tests.UpdateOrCreateTestsWithManualPKs.test_create_with_duplicate_primary_key" ,
106
- # Tests that require savepoints
107
- "admin_views.tests.AdminViewBasicTest.test_disallowed_to_field" ,
108
- "admin_views.tests.AdminViewPermissionsTest.test_add_view" ,
109
- "admin_views.tests.AdminViewPermissionsTest.test_change_view" ,
110
- "admin_views.tests.AdminViewPermissionsTest.test_change_view_save_as_new" ,
111
- "admin_views.tests.AdminViewPermissionsTest.test_delete_view" ,
112
- "auth_tests.test_views.ChangelistTests.test_view_user_password_is_readonly" ,
113
- "fixtures.tests.FixtureLoadingTests.test_loaddata_app_option" ,
114
- "fixtures.tests.FixtureLoadingTests.test_unmatched_identifier_loading" ,
115
- "fixtures_model_package.tests.FixtureTestCase.test_loaddata" ,
116
- "get_or_create.tests.GetOrCreateTests.test_get_or_create_invalid_params" ,
117
- "get_or_create.tests.UpdateOrCreateTests.test_integrity" ,
118
- "many_to_many.tests.ManyToManyTests.test_add" ,
119
- "many_to_one.tests.ManyToOneTests.test_fk_assignment_and_related_object_cache" ,
120
- "model_fields.test_booleanfield.BooleanFieldTests.test_null_default" ,
121
- "model_fields.test_floatfield.TestFloatField.test_float_validates_object" ,
122
- "multiple_database.tests.QueryTestCase.test_generic_key_cross_database_protection" ,
123
- "multiple_database.tests.QueryTestCase.test_m2m_cross_database_protection" ,
124
- }
125
99
126
100
@cached_property
127
101
def django_test_expected_failures (self ):
128
102
expected_failures = super ().django_test_expected_failures
129
103
expected_failures .update (self ._django_test_expected_failures )
130
104
if not self .is_mongodb_6_3 :
131
105
expected_failures .update (self ._django_test_expected_failures_bitwise )
132
- if self .supports_transactions :
133
- expected_failures .update (self ._django_test_expected_failures_transactions )
134
- else :
135
- expected_failures .update (self ._django_test_expected_failures_no_transactions )
136
106
return expected_failures
137
107
138
108
django_test_skips = {
@@ -515,6 +485,17 @@ def django_test_expected_failures(self):
515
485
"Connection health checks not implemented." : {
516
486
"backends.base.test_base.ConnectionHealthChecksTests" ,
517
487
},
488
+ "transaction.atomic() is not supported." : {
489
+ "backends.base.test_base.DatabaseWrapperLoggingTests" ,
490
+ "basic.tests.SelectOnSaveTests.test_select_on_save_lying_update" ,
491
+ "migrations.test_executor.ExecutorTests.test_atomic_operation_in_non_atomic_migration" ,
492
+ "migrations.test_operations.OperationTests.test_run_python_atomic" ,
493
+ },
494
+ "transaction.rollback() is not supported." : {
495
+ "transactions.tests.AtomicMiscTests.test_mark_for_rollback_on_error_in_autocommit" ,
496
+ "transactions.tests.AtomicMiscTests.test_mark_for_rollback_on_error_in_transaction" ,
497
+ "transactions.tests.NonAutocommitTests.test_orm_query_after_error_and_rollback" ,
498
+ },
518
499
"migrate --fake-initial is not supported." : {
519
500
"migrations.test_commands.MigrateTests.test_migrate_fake_initial" ,
520
501
"migrations.test_commands.MigrateTests.test_migrate_fake_split_initial" ,
@@ -609,15 +590,11 @@ def supports_atlas_search(self):
609
590
return True
610
591
611
592
@cached_property
612
- def supports_select_union (self ):
613
- # Stage not supported inside of a multi-document transaction: $unionWith
614
- return not self .supports_transactions
615
-
616
- @cached_property
617
- def supports_transactions (self ):
593
+ def _supports_transactions (self ):
618
594
"""
619
595
Transactions are enabled if MongoDB is configured as a replica set or a
620
- sharded cluster.
596
+ sharded cluster. This is a MongoDB-specific feature flag distinct from Django's
597
+ supports_transactions (without the underscore prefix).
621
598
"""
622
599
self .connection .ensure_connection ()
623
600
client = self .connection .connection .admin
0 commit comments