#33680: Documentation example of customising model instance loading has a bug
-------------------------------------+-------------------------------------
     Reporter:  Ali Toosi            |                    Owner:  Ali Toosi
         Type:  Bug                  |                   Status:  assigned
    Component:  Documentation        |                  Version:  4.0
     Severity:  Normal               |               Resolution:
     Keywords:  documentation,       |             Triage Stage:
  from_db, model instance loading    |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

 * owner:  nobody => Ali Toosi
 * needs_better_patch:  0 => 1
 * status:  new => assigned


Comment:

 Thanks for the ticket.

 > The easiest fix for this is to update the field_names too so they would
 1. work and 2. show which fields were not loaded from the db at the time.

 I'd keep the previous behavior and rather filter out `DEFERRED` from the
 list of values, e.g.
 {{{#!diff
 diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt
 index 3638c6ccff..ec0232673e 100644
 --- a/docs/ref/models/instances.txt
 +++ b/docs/ref/models/instances.txt
 @@ -103,7 +103,9 @@ are loaded from the database::
          instance._state.adding = False
          instance._state.db = db
          # customization to store the original field values on the
 instance
 -        instance._loaded_values = dict(zip(field_names, values))
 +        instance._loaded_values = dict(
 +            zip(field_names, (value for value from values where value is
 not DEFERRED))
 +        )
          return instance

      def save(self, *args, **kwargs):
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33680#comment:2>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018093a1e41f-2c14bd0c-8165-42c9-966d-33df2991e6cb-000000%40eu-central-1.amazonses.com.

Reply via email to