#34012: order_by silently skips non-existing fields of existing related fields
----------------------------------------------+------------------------
               Reporter:  Klaas van Schelven  |          Owner:  nobody
                   Type:  Uncategorized       |         Status:  new
              Component:  Uncategorized       |        Version:  4.0
               Severity:  Normal              |       Keywords:
           Triage Stage:  Unreviewed          |      Has patch:  0
    Needs documentation:  0                   |    Needs tests:  0
Patch needs improvement:  0                   |  Easy pickings:  0
                  UI/UX:  0                   |
----------------------------------------------+------------------------
 Compare the following desirable behavior:

 {{{
 >>> SomeModel.objects.all().order_by("non_existing_field")

 Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File "......lib/python3.10/site-packages/django/db/models/query.py",
 line 1149, in order_by
     obj.query.add_ordering(*field_names)
   File "......lib/python3.10/site-packages/django/db/models/sql/query.py",
 line 2016, in add_ordering
     self.names_to_path(item.split(LOOKUP_SEP), self.model._meta)
   File "......lib/python3.10/site-packages/django/db/models/sql/query.py",
 line 1562, in names_to_path
     raise FieldError("Cannot resolve keyword '%s' into field. "

 django.core.exceptions.FieldError: Cannot resolve keyword
 'non_existing_field' into field. Choices are: [redacted]
 }}}

 with the following undesirable behavior:

 {{{
 >>>
 SomeModel.objects.all().order_by("some_foreign_key__non_existing_field")
 <QuerySet .... [ i.e. shows some results ]
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34012>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701833d6695d2-c8908fa5-a3e2-4f47-976f-5cadf1a9d2c0-000000%40eu-central-1.amazonses.com.

Reply via email to