Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#31660 closed Bug (fixed)

AttributeError is raised while grouping on reverse relation.

Reported by: Tomasz Szymański Owned by: Mariusz Felisiak
Component: Database layer (models, ORM) Version: 3.0
Severity: Release blocker Keywords:
Cc: Mikail Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Aggregation by using StringAgg works in 3.0.6, doesn't in 3.0.7

qs = qs.annotate(
        filtered_attribute=models.FilteredRelation(
            relation_name="attributes",
        ),
        concatenated_values=models.Case(
            models.When(
                models.Q(filtered_attribute=None),
                then=models.Value(""),
            ),
            default=StringAgg(
                models.F("name"),
                delimiter=",",
            ),
            output_field=models.CharField(),
        ),
    )

the exception raised in 3.0.7:

'ManyToOneRel' object has no attribute 'select_format'

Possibly broken by:
https://github.com/django/django/pull/12913

Attatching a zipped project, steps to reproduce:

  • docker-compose build
  • docker-compose docker-compose run web python manage.py migrate
  • docker-compose up
  • Either access localhost:8000/bug or run the tests: docker-compose run web python manage.py test

Attachments (1)

django-bug.zip (15.0 KB ) - added by Tomasz Szymański 4 years ago.
Sample project with the bug-triggering code and testcase implemented

Download all attachments as: .zip

Change History (9)

by Tomasz Szymański, 4 years ago

Attachment: django-bug.zip added

Sample project with the bug-triggering code and testcase implemented

comment:1 by Mariusz Felisiak, 4 years ago

Owner: changed from nobody to Mariusz Felisiak
Severity: NormalRelease blocker
Status: newassigned
Summary: AttributeError is raised while using StringAgg aggregating function on PostgreSQL databases.AttributeError is raised while grouping on reverse relation.
Triage Stage: UnreviewedAccepted

Thanks for the report.

Regression in 3a941230c85b2702a5e1cd97e17251ce21057efa.

comment:2 by Simon Charette, 4 years ago

The fact a ManyToOneRel rel makes it's way there is problematic, that means an expression has output_field: ManyToOneRel.

comment:3 by Mikail, 4 years ago

Cc: Mikail added

comment:4 by Mariusz Felisiak, 4 years ago

Has patch: set

comment:5 by GitHub <noreply@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In 78ad4b4b:

Fixed #31660 -- Fixed queryset crash when grouping by m2o relation.

Regression in 3a941230c85b2702a5e1cd97e17251ce21057efa.

Thanks Tomasz Szymański for the report.

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In df9b9de6:

[3.1.x] Fixed #31660 -- Fixed queryset crash when grouping by m2o relation.

Regression in 3a941230c85b2702a5e1cd97e17251ce21057efa.

Thanks Tomasz Szymański for the report.
Backport of 78ad4b4b0201003792bfdbf1a7781cbc9ee03539 from master

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In be7a2951:

[3.0.x] Fixed #31660 -- Fixed queryset crash when grouping by m2o relation.

Regression in 3a941230c85b2702a5e1cd97e17251ce21057efa.

Thanks Tomasz Szymański for the report.
Backport of 78ad4b4b0201003792bfdbf1a7781cbc9ee03539 from master

comment:8 by GitHub <noreply@…>, 4 years ago

In e2cdbc5:

[3.0.x] Refs #31660 -- Fixed annotations.tests crash on MySQL.

Follow up to be7a295141337189b9eceea506489bdfe07f199e.

Note: See TracTickets for help on using tickets.
Back to Top