Skip to content

support group by in embedded model fields #221

@WaVEV

Description

@WaVEV

Example failure:

Holder.objects.annotate(
    group=ExpressionWrapper(F("data__integer") + 5, output_field=models.IntegerField())
)
.values("group")
.annotate(max_auto_now=Max("data__auto_now"))
.order_by("data__integer")

  File "/home/tim/code/django-mongodb/django_mongodb_backend/compiler.py", line 243, in execute_sql
    self.pre_sql_setup()
  File "/home/tim/code/django-mongodb/django_mongodb_backend/compiler.py", line 219, in pre_sql_setup
    ids, replacements = self._get_group_id_expressions(order_by)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tim/code/django-mongodb/django_mongodb_backend/compiler.py", line 174, in _get_group_id_expressions
    alias, replacement = self._get_group_alias_column(col, annotation_group_idx)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tim/code/django-mongodb/django_mongodb_backend/compiler.py", line 47, in _get_group_alias_column
    col = self._get_column_from_expression(expr, alias)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tim/code/django-mongodb/django_mongodb_backend/compiler.py", line 56, in _get_column_from_expression
    column_target = expr.output_field.__class__()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: EmbeddedModelField.__init__() missing 1 required positional argument: 'embedded_model'

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