django/django — pull request #1325 by koddsson (2013-07-03 15:18:10+00:00)
Title: 20600 - Subqueries should retain ORDER BY when using DISTINCT ON

I tried pinpointing where the bug is occurring but was not successful. Towards the end I started to suspect that the problem is in how the SQL query is executed and thus the problem to be in `sql_with_params()`.

The bug ticket: https://code.djangoproject.com/ticket/20600