#30317: model_to_dict() makes separate db calls for each missing field
-------------------------------------+-------------------------------------
     Reporter:  Chris Hranj          |                    Owner:  nobody
         Type:                       |                   Status:  closed
  Cleanup/optimization               |
    Component:  Forms                |                  Version:  master
     Severity:  Normal               |               Resolution:  wontfix
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

 * status:  new => closed
 * resolution:   => wontfix


Comment:

 Hi Chris.

 Thanks for the report. (Unless you have an unforeseen concrete proposal in
 mind) I think we have to say `wontfix` here.

 `model_to_dict` is just using the field properties. It has no knowledge of
 whether they deferred or not. (And that's not something we'd add there.)

 So, you really need to be passing in objects that already have the
 required fields loaded. That you're not doing this suggests you're over-
 using `only() here. See again the warning note:

 > The defer() method (and its cousin, only(), below) are only for advanced
 use-cases. They provide an optimization for when you have analyzed your
 queries closely and understand exactly what information you need and have
 measured that the difference between returning the fields you need and the
 full set of fields for the model will be significant.

 If you're sure you're using `only()` correctly, your best bet is probably
 to add a `defer(None)` and re-fetch once before running through
 `model_to_dict()`.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30317#comment:1>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.ebb8f81ab9d0022c6e2f43962b22a8df%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to