From 5de21a95377475bf249845aeeb658512b6308ff6 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 17 Oct 2024 19:40:33 -0400 Subject: [PATCH 1/2] add model_inheritanace_regress tests to CI --- .github/workflows/test-python.yml | 1 + django_mongodb/features.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index e412cae32..24a9829a0 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -91,6 +91,7 @@ jobs: migrations model_fields model_forms + model_inheritance_regress mutually_referential nested_foreign_keys null_fk diff --git a/django_mongodb/features.py b/django_mongodb/features.py index 8b0707434..f1eb0f22f 100644 --- a/django_mongodb/features.py +++ b/django_mongodb/features.py @@ -105,6 +105,9 @@ class DatabaseFeatures(BaseDatabaseFeatures): # https://github.com/mongodb-labs/django-mongodb/issues/161 "queries.tests.RelatedLookupTypeTests.test_values_queryset_lookup", "queries.tests.ValuesSubqueryTests.test_values_in_subquery", + # SQLCompiler.collection_name raises StopIteration + "model_inheritance_regress.tests.ModelInheritanceTest.test_mti_update_grand_parent_through_child", + "model_inheritance_regress.tests.ModelInheritanceTest.test_mti_update_parent_through_child", } # $bitAnd, #bitOr, and $bitXor are new in MongoDB 6.3. _django_test_expected_failures_bitwise = { @@ -266,6 +269,7 @@ def django_test_expected_failures(self): "datetimes.tests.DateTimesTests.test_datetimes_has_lazy_iterator", "datetimes.tests.DateTimesTests.test_datetimes_returns_available_dates_for_given_scope_and_given_field", "datetimes.tests.DateTimesTests.test_related_model_traverse", + "model_inheritance_regress.tests.ModelInheritanceTest.test_issue_7105", "queries.tests.Queries1Tests.test_ticket7155", "queries.tests.Queries1Tests.test_tickets_7087_12242", "timezones.tests.LegacyDatabaseTests.test_query_datetimes", From b3fd2c479c653bbe4fe3f1e6c4057ce5bf93711f Mon Sep 17 00:00:00 2001 From: Emanuel Lupi Date: Fri, 18 Oct 2024 00:41:56 -0300 Subject: [PATCH 2/2] fix SQLCompiler.collection_name crash on QuerySet.update() with MTI Regression in e9711203ac720f34ce14ecb53489828887c4ef64. --- django_mongodb/compiler.py | 12 ++++++++++++ django_mongodb/features.py | 3 --- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/django_mongodb/compiler.py b/django_mongodb/compiler.py index d65ae608e..c18754279 100644 --- a/django_mongodb/compiler.py +++ b/django_mongodb/compiler.py @@ -673,6 +673,10 @@ def insert(self, docs, returning_fields=None): inserted_ids = self.collection.insert_many(docs).inserted_ids return inserted_ids if returning_fields else [] + @cached_property + def collection_name(self): + return self.query.get_meta().db_table + class SQLDeleteCompiler(compiler.SQLDeleteCompiler, SQLCompiler): def execute_sql(self, result_type=MULTI): @@ -690,6 +694,10 @@ def check_query(self): def get_where(self): return self.query.where + @cached_property + def collection_name(self): + return self.query.base_table + class SQLUpdateCompiler(compiler.SQLUpdateCompiler, SQLCompiler): def execute_sql(self, result_type): @@ -754,6 +762,10 @@ def check_query(self): def get_where(self): return self.query.where + @cached_property + def collection_name(self): + return self.query.base_table + class SQLAggregateCompiler(SQLCompiler): def build_query(self, columns=None): diff --git a/django_mongodb/features.py b/django_mongodb/features.py index f1eb0f22f..06b3dbfc6 100644 --- a/django_mongodb/features.py +++ b/django_mongodb/features.py @@ -105,9 +105,6 @@ class DatabaseFeatures(BaseDatabaseFeatures): # https://github.com/mongodb-labs/django-mongodb/issues/161 "queries.tests.RelatedLookupTypeTests.test_values_queryset_lookup", "queries.tests.ValuesSubqueryTests.test_values_in_subquery", - # SQLCompiler.collection_name raises StopIteration - "model_inheritance_regress.tests.ModelInheritanceTest.test_mti_update_grand_parent_through_child", - "model_inheritance_regress.tests.ModelInheritanceTest.test_mti_update_parent_through_child", } # $bitAnd, #bitOr, and $bitXor are new in MongoDB 6.3. _django_test_expected_failures_bitwise = {