#26390: order_by('?') unexpectedly breaking queryset aggregation
-------------------------------------+-------------------------------------
Reporter: Tzu-ping Chung | Owner: Tzu-ping
| Chung
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Zach):
If you need to filter on an annotated value while still using
`.order_by('?')`, this could work:
{{{#!python
Thing.objects.filter(pk__in=Thing.objects.annotate(rc=Count('related')).filter(rc__gte=2)).order_by('?')
}}}
This avoids the `GROUP BY RANDOM() ORDER BY RANDOM() ASC` issue while
still allowing `.annotate()` and `.order_by('?')` to be used together.
--
Ticket URL: <https://code.djangoproject.com/ticket/26390#comment:12>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.b1e1210e584d6f747c9e1aeb956325a1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.