Opened 4 weeks ago

Closed 4 weeks ago

Last modified 3 weeks ago

#37047 closed Bug (fixed)

Crash in Query.orderby_issubset_groupby for descending and random order_by strings

Reported by: Anže Pečar Owned by: Anže Pečar
Component: Database layer (models, ORM) Version: dev
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Anže Pečar)

#26434 caused a crash. It can be reproduced with:

User.objects.values("is_staff").annotate(latest=Max("date_joined")).order_by("-latest").count()

You should see the following exception:

django.core.exceptions.FieldError: Cannot resolve keyword '-latest' into field. Choices are: activity_logs, date_joined, email, first_name, groups, id, is_active, is_administrator, is_staff, is_superuser, last_login, last_name, latest, logentry, module_access, password, user_permissions, username

Change History (5)

comment:1 by Anže Pečar, 4 weeks ago

Description: modified (diff)

comment:2 by Jacob Walls, 4 weeks ago

Owner: set to Anže Pečar
Severity: NormalRelease blocker
Status: newassigned
Triage Stage: UnreviewedAccepted

Reproduced, thanks for testing the main branch!

comment:3 by Jacob Walls, 4 weeks ago

Triage Stage: AcceptedReady for checkin

comment:4 by Jacob Walls <jacobtylerwalls@…>, 4 weeks ago

Resolution: fixed
Status: assignedclosed

In a284a49:

Fixed #37047 -- Fixed crash in Query.orderby_issubset_groupby for descending and random order_by strings.

Run this example:

`python
User.objects.values("is_staff").annotate(latest=Max("date_joined")).order_by("-latest").count()
`

You should see the following exception:

`
django.core.exceptions.FieldError: Cannot resolve keyword '-latest' into field.
`

Regression in 2ce5cb0f7a4618dfdc5f5c10e53e2e9b9543d298.

comment:5 by Michal Mládek, 3 weeks ago

I’d like to thank you for catching these two edge cases. Great work.

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