Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#28266 closed Bug (fixed)

Typo in docs/ref/models/instances.txt Model.from_db() code example

Reported by: Lachlan Musicman Owned by: nobody
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

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

Attachments (1)

16df9cb6cc6188a53de32bbdcbb25fba54d83aa5.patch (1002 bytes ) - added by Lachlan Musicman 7 years ago.
Patch file

Download all attachments as: .zip

Change History (5)

by Lachlan Musicman, 7 years ago

Patch file

comment:1 by Tim Graham, 7 years ago

Summary: from_db example in instance.txt doesn't workTypo in docs/ref/models/instances.txt Model.from_db() code example
Triage Stage: UnreviewedReady for checkin
Type: UncategorizedBug

comment:2 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: newclosed

In 00093da:

Fixed #28266 -- Fixed typo in docs/ref/models/instances.txt.

comment:3 by Tim Graham <timograham@…>, 7 years ago

In 84dac491:

[1.11.x] Fixed #28266 -- Fixed typo in docs/ref/models/instances.txt.

Backport of 00093daec9cc61d8af7fcebdbe58e263bea935a3 from master

comment:4 by Tim Graham <timograham@…>, 7 years ago

In 7b2d4a95:

[1.10.x] Fixed #28266 -- Fixed typo in docs/ref/models/instances.txt.

Backport of 00093daec9cc61d8af7fcebdbe58e263bea935a3 from master

Note: See TracTickets for help on using tickets.
Back to Top