Opened 6 years ago

Closed 6 years ago

#23571 closed Bug (worksforme)

Empty order_by() doesn't work with slice

Reported by: None Owned by: None
Component: Database layer (models, ORM) Version: 1.7
Severity: Normal Keywords: order_by, slice
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

MyModel.objects.order_by() - use SQL without ORDER BY.
MyModel.objects.order_by()[:10] - use SQL with ORDER BY (default fields for model ordering).

This is a bug or a feature? :)

Change History (2)

comment:1 Changed 6 years ago by ILYA

Are you sure? How have you checked that ordering is applied? I've checked it in my project and everything works as expected (no ordering in both cases).

comment:2 Changed 6 years ago by Tim Graham

Resolution: worksforme
Status: newclosed

I also cannot reproduce the reported issue:

I added:

class Meta:
    ordering = ('id',)

to the Poll class in the tutorial.

>>> str(Poll.objects.all().query)
'SELECT "polls_poll"."id", "polls_poll"."question", "polls_poll"."pub_date" FROM "polls_poll" ORDER BY "polls_poll"."id" ASC'
>>> str(Poll.objects.order_by().query)
'SELECT "polls_poll"."id", "polls_poll"."question", "polls_poll"."pub_date" FROM "polls_poll"'
>>> str(Poll.objects.order_by()[:10].query)
'SELECT "polls_poll"."id", "polls_poll"."question", "polls_poll"."pub_date" FROM "polls_poll" LIMIT 10'
Note: See TracTickets for help on using tickets.
Back to Top