Skip to content

Commit b3fd2c4

Browse files
WaVEVtimgraham
authored andcommitted
fix SQLCompiler.collection_name crash on QuerySet.update() with MTI
Regression in e971120.
1 parent 5de21a9 commit b3fd2c4

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

django_mongodb/compiler.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@ def insert(self, docs, returning_fields=None):
673673
inserted_ids = self.collection.insert_many(docs).inserted_ids
674674
return inserted_ids if returning_fields else []
675675

676+
@cached_property
677+
def collection_name(self):
678+
return self.query.get_meta().db_table
679+
676680

677681
class SQLDeleteCompiler(compiler.SQLDeleteCompiler, SQLCompiler):
678682
def execute_sql(self, result_type=MULTI):
@@ -690,6 +694,10 @@ def check_query(self):
690694
def get_where(self):
691695
return self.query.where
692696

697+
@cached_property
698+
def collection_name(self):
699+
return self.query.base_table
700+
693701

694702
class SQLUpdateCompiler(compiler.SQLUpdateCompiler, SQLCompiler):
695703
def execute_sql(self, result_type):
@@ -754,6 +762,10 @@ def check_query(self):
754762
def get_where(self):
755763
return self.query.where
756764

765+
@cached_property
766+
def collection_name(self):
767+
return self.query.base_table
768+
757769

758770
class SQLAggregateCompiler(SQLCompiler):
759771
def build_query(self, columns=None):

django_mongodb/features.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
105105
# https://github.com/mongodb-labs/django-mongodb/issues/161
106106
"queries.tests.RelatedLookupTypeTests.test_values_queryset_lookup",
107107
"queries.tests.ValuesSubqueryTests.test_values_in_subquery",
108-
# SQLCompiler.collection_name raises StopIteration
109-
"model_inheritance_regress.tests.ModelInheritanceTest.test_mti_update_grand_parent_through_child",
110-
"model_inheritance_regress.tests.ModelInheritanceTest.test_mti_update_parent_through_child",
111108
}
112109
# $bitAnd, #bitOr, and $bitXor are new in MongoDB 6.3.
113110
_django_test_expected_failures_bitwise = {

0 commit comments

Comments
 (0)