Skip to content

Commit

Permalink
fix SQLCompiler.collection_name crash on QuerySet.update() with MTI
Browse files Browse the repository at this point in the history
Regression in e971120.
  • Loading branch information
WaVEV authored and timgraham committed Oct 21, 2024
1 parent 5de21a9 commit b3fd2c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 12 additions & 0 deletions django_mongodb/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 0 additions & 3 deletions django_mongodb/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit b3fd2c4

Please sign in to comment.