#14766: ordering by a field that does not exists returns an empty QuerySet
---------------------------------------------------+------------------------
          Reporter:  robhudson                     |         Owner:  nobody     
           
            Status:  reopened                      |     Milestone:             
           
         Component:  Database layer (models, ORM)  |       Version:  1.2        
           
        Resolution:                                |      Keywords:  
sprintdec2010 order_by
             Stage:  Accepted                      |     Has_patch:  1          
           
        Needs_docs:  0                             |   Needs_tests:  0          
           
Needs_better_patch:  1                             |  
---------------------------------------------------+------------------------
Comment (by kmtracey):

 I don't have a Mac, but I cannot recreate the original problem with the
 Python 2.7.1 I have available to me (Windows):

 {{{
 Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit
 (Intel)] on win32
 Type "help", "copyright", "credits" or "license" for more information.
 (InteractiveConsole)
 >>> from django.contrib.contenttypes.models import ContentType
 >>> ContentType.objects.order_by('monkeys')
 Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File "C:\u\kmt\django\trunk\django\db\models\query.py", line 69, in
 __repr__
     data = list(self[:REPR_OUTPUT_SIZE + 1])
   File "C:\u\kmt\django\trunk\django\db\models\query.py", line 84, in
 __len__
     self._result_cache.extend(list(self._iter))
   File "C:\u\kmt\django\trunk\django\db\models\query.py", line 273, in
 iterator
     for row in compiler.results_iter():
   File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line 680,
 in results_iter
     for rows in self.execute_sql(MULTI):
   File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line 725,
 in execute_sql
     sql, params = self.as_sql()
   File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line 60,
 in as_sql
     ordering, ordering_group_by = self.get_ordering()
   File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line 349,
 in get_ordering
     self.query.model._meta, default_order=asc):
   File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line 378,
 in find_ordering_name
     opts, alias, False)
   File "C:\u\kmt\django\trunk\django\db\models\sql\query.py", line 1215,
 in setup_joins
     "Choices are: %s" % (name, ", ".join(names)))
 FieldError: Cannot resolve keyword 'monkeys' into field. Choices are:
 app_label, id, logentry, model, name, permission
 }}}

 So it does not look like the problem re-appeared in Python 2.7 generally,
 and it does not seem like the kind of bug that would appear in just one
 distro, so I'm confused by the report that it exists in the Mac version of
 2.7.1.

 (Some history of Django's encounters with this Python bug, and a link to
 the Python bug, can be found in #7786. In that ticket Malcolm indicated it
 would be quite difficult to attempt to avoid raising any exceptions in
 `__len__`, and the "fix" for the test that was failing as a result was
 just to skip it on Pythons known to have the problem.)

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14766#comment:12>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to