Opened 4 weeks ago
Closed 3 weeks ago
#37278 closed Cleanup/optimization (fixed)
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: | Ready for checkin |
| 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 (5)
comment:1 by , 4 weeks ago
| Triage Stage: | Unreviewed → Accepted |
|---|---|
| Type: | Bug → Cleanup/optimization |
comment:2 by , 4 weeks ago
| Severity: | Release blocker → Normal |
|---|---|
| Summary: | QuerySet.totally_ordered property doesn't fathom annotations → QuerySet.totally_ordered property doesn't fathom aliases of pure fields |
comment:4 by , 3 weeks ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Simon reviewed and approved on GitHub.
Note:
See TracTickets
for help on using tickets.
QuerySet.totally_orderedwill 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.annotationentries that areColobjects then I think this ticket is acceptable as an optimization.Since the return type of
totally_orderedisFalseeven when it's unknown (but potentiallyTrue) I consider this is an optimization and not a bug.