--
Ticket URL: <https://code.djangoproject.com/ticket/17990>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_docs: => 0
* needs_better_patch: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted
Comment:
I don't think this will be easy to fix. The obvious fix is to add the
random() to the select distinct list, but that of course breaks the
distinct (you are doing distinct on random(), which isn't wanted). The
only solution I can see is using an inner query with the distinct, then
ordering by random() in the outer query. It should be possible to do. The
usecase isn't common and the patch will likely be nontrivial.
--
Ticket URL: <https://code.djangoproject.com/ticket/17990#comment:1>
Comment (by anonymous):
I solved this problem using GROUP BY instead of DISTINCT. I found this
solution here:
http://stackoverflow.com/questions/9538578/
--
Ticket URL: <https://code.djangoproject.com/ticket/17990#comment:2>
Comment (by gcbirzan):
Actually, an even easier fix would be to exclude the RANDOM from the
distinct. That's in a patch. In a trivial case, that can be worked around
like this:
Model.objects.extra(select={'rand':
'RANDOM()'}).distinct('pk').order_by('rand')
--
Ticket URL: <https://code.djangoproject.com/ticket/17990#comment:3>
* cc: Étienne Beaulé (added)
* status: new => closed
* resolution: => fixed
Comment:
Fixed in 0c7633178fa9410f102e4708cef979b873bccb76
--
Ticket URL: <https://code.djangoproject.com/ticket/17990#comment:4>
* Attachment "test-17990.diff" added.
Regression test.
* status: closed => new
* resolution: fixed =>
Comment:
It doesn't crash but it's not fixed, see
[https://code.djangoproject.com/ticket/17990#comment:1 Anssi's comment]. I
attached a regression test.
--
Ticket URL: <https://code.djangoproject.com/ticket/17990#comment:6>
* owner: nobody => Ryan Cheley
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/17990#comment:7>
* status: assigned => closed
* resolution: => duplicate
Comment:
The solution offered by Anssi Kääriäinen and supported by the
stackoverflow answer in ticket:17990#comment:2 point to this being a
subset of the solution being worked on in 24462. Therefore it is being
marked as resolved - duplicate
--
Ticket URL: <https://code.djangoproject.com/ticket/17990#comment:8>