{{{
class Test(Model):
name = CharField(max_length=50)
class Meta(object):
db_table = 'test'
}}}
{{{Test.objects.extra(order_by=['-name'])}}} should be converted to
something like {{{SELECT * FROM test ORDER BY name DESC}}}, but instead it
becomes {{{SELECT * FROM test ORDER BY name ASC}}}. The minus is ignored.
It wasn’t happening in Django 1.6 and 1.7.
(This issue was discovered in [https://github.com/BertrandBordage/django-
cachalot/blob/c578cbff8a931d8bec3c3e026c8908cb61bf71d4/cachalot/tests/read.py#L495-501
the test suite of django-cachalot])
--
Ticket URL: <https://code.djangoproject.com/ticket/24174>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => assigned
* needs_better_patch: => 0
* needs_tests: => 0
* owner: nobody => jarshwah
* needs_docs: => 0
* stage: Unreviewed => Accepted
Comment:
Based on looking at the models of the linked test suite I'm guessing that
this is hitting the "duplicate" order by clause. It's keeping the default
ordering of the model, which is by name ascending, and removing the extra
which is by name descending. Extra ordering should prevent the default
ordering from being applied, and the negative sign should be preserved.
--
Ticket URL: <https://code.djangoproject.com/ticket/24174#comment:1>
Comment (by BertrandBordage):
I tested without default ordering, the issue is still there.
But I wasn’t precise enough in my report, it’s only happening when we
specify the table name:
{{{
>>> print Test.objects.all().query
SELECT […] FROM "test"
>>> print Test.objects.extra(order_by=['-name']).query
SELECT […] FROM "test" ORDER BY "test"."name" DESC
>>> print Test.objects.extra(order_by=['-test.name']).query
SELECT […] FROM "test" ORDER BY ("test".name) ASC
>>> print Test.objects.extra(order_by=['-"test"."name"']).query
SELECT […] FROM "test" ORDER BY ("test"."name") ASC
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24174#comment:2>
Comment (by jarshwah):
Thanks for the follow up. That makes it even easier to track down.
This is the block responsible, and should be fairly trivial to fix.
--
Ticket URL: <https://code.djangoproject.com/ticket/24174#comment:3>
* has_patch: 0 => 1
* stage: Accepted => Ready for checkin
Comment:
https://github.com/django/django/pull/3947
--
Ticket URL: <https://code.djangoproject.com/ticket/24174#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"69c6a6868f0b4137bb293ff4326ecf4681506c37"]:
{{{
#!CommitTicketReference repository=""
revision="69c6a6868f0b4137bb293ff4326ecf4681506c37"
Fixed #24174 -- Fixed extra order by descending
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24174#comment:5>
Comment (by Josh Smeaton <josh.smeaton@…>):
In [changeset:"0c910823c166b827b090df5c5c8be9e502a14d8c"]:
{{{
#!CommitTicketReference repository=""
revision="0c910823c166b827b090df5c5c8be9e502a14d8c"
[1.8.x] Fixed #24174 -- Fixed extra order by descending
Backport of 69c6a6868f0b4137bb293ff4326ecf4681506c37 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24174#comment:6>