diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 253febd3d..e8c53d814 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -91,6 +91,7 @@ jobs: m2m_through m2o_recursive model_fields + one_to_one ordering or_lookups queries.tests.Ticket12807Tests.test_ticket_12807 diff --git a/README.md b/README.md index dbf2f1478..a7e97e6d7 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,7 @@ Migrations for 'admin': - `aggregate()` - `dates()` - `datetimes()` + - `delete()`, if the query uses multiple collections. - `distinct()` - `extra()` - `prefetch_related()` diff --git a/django_mongodb/compiler.py b/django_mongodb/compiler.py index 5d230d238..7f293dd01 100644 --- a/django_mongodb/compiler.py +++ b/django_mongodb/compiler.py @@ -267,12 +267,19 @@ def insert(self, docs, returning_fields=None): return inserted_ids if returning_fields else [] -class SQLDeleteCompiler(SQLCompiler): +class SQLDeleteCompiler(compiler.SQLDeleteCompiler, SQLCompiler): def execute_sql(self, result_type=MULTI): cursor = Cursor() cursor.rowcount = self.build_query([self.query.get_meta().pk]).delete() return cursor + def check_query(self): + super().check_query() + if not self.single_alias: + raise NotSupportedError( + "Cannot use QuerySet.delete() when querying across multiple collections on MongoDB." + ) + class SQLUpdateCompiler(SQLCompiler): def execute_sql(self, result_type): diff --git a/django_mongodb/features.py b/django_mongodb/features.py index 47ebaa1ba..e94662047 100644 --- a/django_mongodb/features.py +++ b/django_mongodb/features.py @@ -104,6 +104,9 @@ class DatabaseFeatures(BaseDatabaseFeatures): "annotations.tests.AliasTests.test_order_by_alias", # annotate() + values_list() + order_by() loses annotated value. "expressions_case.tests.CaseExpressionTests.test_annotate_values_not_in_order_by", + # Querying the reverse side of a foreign key for None returns no + # results: https://github.com/mongodb-labs/django-mongodb/issues/76 + "one_to_one.tests.OneToOneTests.test_filter_one_to_one_relations", } # $bitAnd, #bitOr, and $bitXor are new in MongoDB 6.3. _django_test_expected_failures_bitwise = { @@ -353,6 +356,8 @@ def django_test_expected_failures(self): "lookup.tests.LookupTests.test_exact_sliced_queryset_limit_one_offset", "lookup.tests.LookupTests.test_in_different_database", "model_fields.test_jsonfield.TestQuerying.test_usage_in_subquery", + "one_to_one.tests.OneToOneTests.test_get_prefetch_queryset_warning", + "one_to_one.tests.OneToOneTests.test_rel_pk_subquery", }, "Count doesn't work in QuerySet.annotate()": { "annotations.tests.AliasTests.test_alias_annotate_with_aggregation", @@ -361,6 +366,9 @@ def django_test_expected_failures(self): "annotations.tests.NonAggregateAnnotationTestCase.test_annotate_with_aggregation", "db_functions.comparison.test_cast.CastTests.test_cast_from_db_datetime_to_date_group_by", }, + "Cannot use QuerySet.delete() when querying across multiple collections on MongoDB.": { + "one_to_one.tests.OneToOneTests.test_o2o_primary_key_delete", + }, "QuerySet.dates() is not supported on MongoDB.": { "annotations.tests.AliasTests.test_dates_alias", "dates.tests.DatesTests.test_dates_trunc_datetime_fields",