Opened 99 minutes ago

Last modified 10 minutes ago

#37278 assigned Cleanup/optimization

QuerySet.totally_ordered property doesn't fathom aliases of pure fields

Reported by: Jacob Walls Owned by: Jacob Walls
Component: Database layer (models, ORM) Version: 6.1
Severity: Normal Keywords:
Cc: VIZZARD-X Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In #36857 we added a public totally_ordered property on QuerySet by porting some logic from the admin.

We didn't check whether F() objects might refer to annotations.

class PhotoOfTheDay(models.Model):
    day = models.DateField(unique=True)

>>> PhotoOfTheDay.objects.order_by("day").totally_ordered
True
>>> PhotoOfTheDay.objects.annotate(día=models.F("day")).order_by("día").totally_ordered
False  # expected True

I'm cooking up a solution 🍲

Change History (3)

comment:1 by Simon Charette, 60 minutes ago

Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

QuerySet.totally_ordered will always have false negatives (e.g. order_by(Upper("pk")) is totally ordered for case-insensitive pks) but as long as this ticket is limited to resolving string references to .annotation entries that are Col objects then I think this ticket is acceptable as an optimization.

Since the return type of totally_ordered is False even when it's unknown I consider this is an optimization and not a bug.

Version 1, edited 55 minutes ago by Simon Charette (previous) (next) (diff)

comment:2 by Jacob Walls, 50 minutes ago

Severity: Release blockerNormal
Summary: QuerySet.totally_ordered property doesn't fathom annotationsQuerySet.totally_ordered property doesn't fathom aliases of pure fields

comment:3 by Jacob Walls, 10 minutes ago

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