Opened 5 months ago

Closed 5 months ago

Last modified 4 months 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: NyanKiyoshi 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 5 months ago.
Sample project with the bug-triggering code and testcase implemented

Download all attachments as: .zip

Change History (9)

Changed 5 months ago by Tomasz Szymański

Attachment: django-bug.zip added

Sample project with the bug-triggering code and testcase implemented

comment:1 Changed 5 months ago by Mariusz Felisiak

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 Changed 5 months ago by Simon Charette

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

comment:3 Changed 5 months ago by NyanKiyoshi

Cc: NyanKiyoshi added

comment:4 Changed 5 months ago by Mariusz Felisiak

Has patch: set

comment:5 Changed 5 months ago by GitHub <noreply@…>

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 Changed 5 months ago by Mariusz Felisiak <felisiak.mariusz@…>

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 Changed 5 months ago by Mariusz Felisiak <felisiak.mariusz@…>

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 Changed 4 months ago by GitHub <noreply@…>

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