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 , 60 minutes ago
| Triage Stage: | Unreviewed → Accepted |
|---|---|
| Type: | Bug → Cleanup/optimization |
comment:2 by , 50 minutes 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 |
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 I consider this is an optimization and not a bug.