@@ -36,6 +36,9 @@ 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, this backend will not
40
+ # support the transaction.atomic() API.
41
+ supports_transactions = False
39
42
supports_unspecified_pk = True
40
43
uses_savepoints = False
41
44
@@ -92,47 +95,13 @@ class DatabaseFeatures(BaseDatabaseFeatures):
92
95
"expressions.tests.ExpressionOperatorTests.test_lefthand_bitwise_xor_right_null" ,
93
96
"expressions.tests.ExpressionOperatorTests.test_lefthand_transformed_field_bitwise_or" ,
94
97
}
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
98
126
99
@cached_property
127
100
def django_test_expected_failures (self ):
128
101
expected_failures = super ().django_test_expected_failures
129
102
expected_failures .update (self ._django_test_expected_failures )
130
103
if not self .is_mongodb_6_3 :
131
104
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
105
return expected_failures
137
106
138
107
django_test_skips = {
@@ -515,6 +484,17 @@ def django_test_expected_failures(self):
515
484
"Connection health checks not implemented." : {
516
485
"backends.base.test_base.ConnectionHealthChecksTests" ,
517
486
},
487
+ "transaction.atomic() is not supported." : {
488
+ "backends.base.test_base.DatabaseWrapperLoggingTests" ,
489
+ "basic.tests.SelectOnSaveTests.test_select_on_save_lying_update" ,
490
+ "migrations.test_executor.ExecutorTests.test_atomic_operation_in_non_atomic_migration" ,
491
+ "migrations.test_operations.OperationTests.test_run_python_atomic" ,
492
+ },
493
+ "transaction.rollback() is not supported." : {
494
+ "transactions.tests.AtomicMiscTests.test_mark_for_rollback_on_error_in_autocommit" ,
495
+ "transactions.tests.AtomicMiscTests.test_mark_for_rollback_on_error_in_transaction" ,
496
+ "transactions.tests.NonAutocommitTests.test_orm_query_after_error_and_rollback" ,
497
+ },
518
498
"migrate --fake-initial is not supported." : {
519
499
"migrations.test_commands.MigrateTests.test_migrate_fake_initial" ,
520
500
"migrations.test_commands.MigrateTests.test_migrate_fake_split_initial" ,
@@ -609,15 +589,11 @@ def supports_atlas_search(self):
609
589
return True
610
590
611
591
@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 ):
592
+ def _supports_transactions (self ):
618
593
"""
619
594
Transactions are enabled if MongoDB is configured as a replica set or a
620
- sharded cluster.
595
+ sharded cluster. It's prefixed with an underscore because this backend does
596
+ the usual Django API: transaction.atomic().
621
597
"""
622
598
self .connection .ensure_connection ()
623
599
client = self .connection .connection .admin
0 commit comments