#33680: Documentation example of customising model instance loading has a bug
-------------------------------------+-------------------------------------
     Reporter:  Ali-Toosi            |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    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:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Ali-Toosi):

 * has_patch:  0 => 1


Old description:

> The docs provide an example of how the model instance loading can be
> changed and how `_loaded_values` can be saved for future comparison here:
> https://docs.djangoproject.com/en/4.0/ref/models/instances/
>
> In this example, it checks if there are any values not loaded from db
> then add them as DEFERRED values so class instantiation would work
> (`cls(*values)`). However, this would mean `values` list has items now
> that do not map to any `field_names` so when at the end of the function,
> we zip them together and store in `_loaded_values`, the code will fail.
>
> 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.

New description:

 The docs provide an example of how the model instance loading can be
 changed and how `_loaded_values` can be saved for future comparison here:
 https://docs.djangoproject.com/en/4.0/ref/models/instances/

 In this example, it checks if there are any values not loaded from db then
 add them as DEFERRED values so class instantiation would work
 (`cls(*values)`). However, this would mean `values` list has items now
 that do not map to any `field_names` so when at the end of the function,
 we zip them together and store in `_loaded_values`, the code will fail.

 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've opened a PR for this here:
 https://github.com/django/django/pull/15664

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33680#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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018093992c44-f6c6b328-5569-4f5c-8c1b-14de6dc12484-000000%40eu-central-1.amazonses.com.

Reply via email to