#28266: from_db example in instance.txt doesn't work
--------------------------------------------+------------------------
               Reporter:  Lachlan Musicman  |          Owner:  nobody
                   Type:  Uncategorized     |         Status:  new
              Component:  Documentation     |        Version:  master
               Severity:  Normal            |       Keywords:
           Triage Stage:  Unreviewed        |      Has patch:  1
    Needs documentation:  0                 |    Needs tests:  0
Patch needs improvement:  0                 |  Easy pickings:  1
                  UI/UX:  0                 |
--------------------------------------------+------------------------
 I think it's because of a mislabelling. Note that a new cls is created and
 it's called new. After that it's referred to as instance.

 {{{
 @classmethod
 def from_db(cls, db, field_names, values):
     # Default implementation of from_db() (subject to change and could
     # be replaced with super()).
     if len(values) != len(cls._meta.concrete_fields):
         values = list(values)
         values.reverse()
         values = [
             values.pop() if f.attname in field_names else DEFERRED
             for f in cls._meta.concrete_fields
         ]
     new = cls(*values)
     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))
     return instance
 }}}

 Should be

 {{{
     instance = cls(*values)
     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))
     return instance
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28266>
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/050.9fc88b67ee7db83751f02fe9b5239673%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to