@@ -36,6 +36,10 @@ class DatabaseFeatures(BaseDatabaseFeatures):
3636 supports_temporal_subtraction = True
3737 # MongoDB stores datetimes in UTC.
3838 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
3943 supports_unspecified_pk = True
4044 uses_savepoints = False
4145
@@ -92,47 +96,13 @@ class DatabaseFeatures(BaseDatabaseFeatures):
9296 "expressions.tests.ExpressionOperatorTests.test_lefthand_bitwise_xor_right_null" ,
9397 "expressions.tests.ExpressionOperatorTests.test_lefthand_transformed_field_bitwise_or" ,
9498 }
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- }
12599
126100 @cached_property
127101 def django_test_expected_failures (self ):
128102 expected_failures = super ().django_test_expected_failures
129103 expected_failures .update (self ._django_test_expected_failures )
130104 if not self .is_mongodb_6_3 :
131105 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 )
136106 return expected_failures
137107
138108 django_test_skips = {
@@ -515,6 +485,17 @@ def django_test_expected_failures(self):
515485 "Connection health checks not implemented." : {
516486 "backends.base.test_base.ConnectionHealthChecksTests" ,
517487 },
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+ },
518499 "migrate --fake-initial is not supported." : {
519500 "migrations.test_commands.MigrateTests.test_migrate_fake_initial" ,
520501 "migrations.test_commands.MigrateTests.test_migrate_fake_split_initial" ,
@@ -609,15 +590,11 @@ def supports_atlas_search(self):
609590 return True
610591
611592 @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 ):
618594 """
619595 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).
621598 """
622599 self .connection .ensure_connection ()
623600 client = self .connection .connection .admin
0 commit comments