#35309: Elide ordering of prefetch querysets for single valued relationships
-------------------------------------+-------------------------------------
     Reporter:  Laurent Lyaudet      |                    Owner:  Laurent
         Type:                       |  Lyaudet
  Cleanup/optimization               |                   Status:  assigned
    Component:  Database layer       |                  Version:  5.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  prefetch single-     |             Triage Stage:  Accepted
  valued order_by                    |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Laurent Lyaudet):

 Hello,


 Thanks for the replies and the constructive suggested improvements.


 I removed `_do_not_modify_order_by`.


 I improved to avoid an useless cloning of `QuerySet`.
 For that I created a protected method
 `QuerySet._in_place_empty_order_by()` just below `QuerySet.order_by()`.
 I thought it would be the best solution without modifying the "public API"
 of `QuerySet`.
 Another solution could be to add kwargs to `QuerySet.order_by()` like :
 - `clone: bool = True`, or `no_clone: bool = False`, or `in_place: bool =
 False`,
 - and maybe `clear_default: bool = False`.
 But it would require a larger discussion I think.
 If you think the name of `QuerySet._in_place_empty_order_by()` should be
 changed for something else, tell me.


 Regarding the tests, thanks for the suggestions.
 I applied them in my two tests.
 I think this is better practice to have two separate tests where the
 intent of each test is clear.
 And I haven't added the asserts in other tests.
 However, I understand that you may want to avoid cluttering the tests and
 the models in `tests/prefetch_related/models.py`.
 I have see that I can replace the class `A35309` with the class `Book` and
 the class `B35309` with the class `Author` in my first test.
 Tell me if you think I should do that.
 I have see that I can replace the class `A35309` with the class `Room` and
 the class `C35309` with the class `House` in my second test.
 Tell me if you think I should do that.

 Best regards,
      Laurent Lyaudet
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35309#comment:11>
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/0107018e48962424-7674d820-9786-4069-98ae-9f5ff2518da9-000000%40eu-central-1.amazonses.com.

Reply via email to