Skip to content

QuerySet.update() with MTI crashes SQLCompiler.collection_name with StopIteration #165

@timgraham

Description

@timgraham

After e971120 (support for subqueries), a couple of model inheritance tests fail like so:

======================================================================
ERROR: test_mti_update_grand_parent_through_child (model_inheritance_regress.tests.ModelInheritanceTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/django-mongodb/django-mongodb/django_repo/tests/model_inheritance_regress/tests.py", line 676, in test_mti_update_grand_parent_through_child
    Senator.objects.update(title="senator 1")
  File "/home/runner/work/django-mongodb/django-mongodb/django_repo/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/runner/work/django-mongodb/django-mongodb/django_repo/django/db/models/query.py", line 1253, in update
    rows = query.get_compiler(self.db).execute_sql(CURSOR)
  File "/home/runner/work/django-mongodb/django-mongodb/django_mongodb/compiler.py", line 731, in execute_sql
    criteria = self.build_query().mongo_query
  File "/home/runner/work/django-mongodb/django-mongodb/django_mongodb/compiler.py", line 390, in build_query
    query = self.query_class(self)
  File "/home/runner/work/django-mongodb/django-mongodb/django_mongodb/query.py", line 50, in __init__
    self.collection = self.compiler.collection
  File "/home/runner/work/django-mongodb/django-mongodb/django_repo/django/utils/functional.py", line 47, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/runner/work/django-mongodb/django-mongodb/django_mongodb/compiler.py", line 468, in collection
    return self.connection.get_collection(self.collection_name)
  File "/home/runner/work/django-mongodb/django-mongodb/django_repo/django/utils/functional.py", line 47, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/runner/work/django-mongodb/django-mongodb/django_mongodb/compiler.py", line 459, in collection_name
    base_table = next(
StopIteration

Make the fix on top of the commit here: https://github.com/mongodb-labs/django-mongodb/compare/main...timgraham:mti-update-stopiteration?expand=1

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions