#34012: QuerySet.order_by() silently skips non-existing fields on related 
fields.
-------------------------------------+-------------------------------------
     Reporter:  Klaas van Schelven   |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Database layer       |                  Version:  4.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by David Sanders):

 felixx this looks like an issue with overriding the foreign model's
 ordering.

 If I repeat the test with Klaas' models and print the query it reveals it
 still attempts to use `parent.id`:


 {{{
 class Parent(Model):
     class Meta:
         ordering = ["id"]

 class Child(Model):
     parent = ForeignKey(Parent, on_delete=CASCADE)

 print(Child.objects.all().order_by('parent__asdf').query)
 SELECT "sample_child"."id", "sample_child"."parent_id" FROM "sample_child"
 INNER JOIN "sample_parent" ON ("sample_child"."parent_id" =
 "sample_parent"."id") ORDER BY "sample_parent"."id" ASC
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34012#comment:4>
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/010701834afe08bf-28b26919-fe28-4ccc-a1f4-12073912899c-000000%40eu-central-1.amazonses.com.

Reply via email to