Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#13490 closed (invalid)

Django's `order_by` Performs Differently Based on Environment

Reported by: b14ck Owned by: nobody
Component: Uncategorized Version: master
Severity: Keywords: database, query, order_by, inconsistency
Cc: rdegges@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Hi there. I came across the following (seemingly) inconsistency with Django's order_by method, that is usually used on DB queries. It appears to act differently when used in production vs. when used through python manage.py shell:

# from python manage.py shell

rdegges@WEB01:~/partyline_portal$ python manage.py shell
Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from partyline_portal.partylines.models import Partyline
>>> partylines = Partyline.objects.all()
>>> partylines
[<Partyline: Randall Test>]
>>> partylines = Partyline.objects.all().order_by('name')
>>> partylines
[<Partyline: Randall Test>]
>>> partylines = Partyline.objects.all()
>>> partylines
[<Partyline: Randall Test>]
>>> partylines.order_by('name')
[<Partyline: Randall Test>]
>>>

As you can see above, I can use the order_by function on both queries: Partyline.objects.all().order_by('name') as well as lists: partylines.order_by('name')

However, if I run this same code in a view, and render a page to the user, Django spits an error saying that partylines has no method order_by available to it.

Attachments (0)

Change History (2)

comment:1 Changed 4 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

I can't find any evidence that this is happening. A queryset is a queryset, and querysets have an order_by method. You haven't provided sample view code; I can only presume that your view has an error of some kind.

comment:2 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.