Changes between Initial Version and Version 3 of Ticket #37436


Ignore:
Timestamp:
Oct 22, 2026, 5:08:46 PM (2 weeks ago)
Author:
Jacob Walls
Comment:

Thanks for the reports. Next time, please present separate reports for separate bugs. Also, for the second issue, it would have been helpful to include the reproducer instead of just reasoning about the code.

I feel more sure about accepting the issue for the KeyError in in_bulk().

I suppose we can also accept the issue for the "don't fetch over an already set value", but I'll CC Adam to see if they have any opinions on that. The proposal is coherent with how .defer() works today -- accessing doesn't overwrite.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #37436

    • Property Triage Stage Unreviewed → Accepted
    • Property Has patch set
    • Property Patch needs improvement set
    • Property Owner changed from Patel Namraa to Adam Johnson
    • Property Severity Normal → Release blocker
  • Ticket #37436 – Description

    initial v3  
    66
    77Consider two objects loaded with a deferred field using FETCH_PEERS:
    8 
     8{{{#!py
    99class Author(models.Model):
    1010name = models.CharField(max_length=100)
    … …  
    1919
    2020_ = authors[1].name
    21 
     21}}}
    2222Fetching authors[1].name causes fetch_many() to populate the field on all peers. This also replaces authors[0].name with the value currently stored in the database.
    2323
    … …  
    3131
    3232fetch_many() uses in_bulk() to retrieve the deferred values and then indexes the returned dictionary for every peer:
    33 
     33{{{#!py
    3434value_by_pk = (
    3535self.field.model._base_manager.using(db)
    … …  
    3939
    4040for instance in instances:
    41 setattr(instance, attname, value_by_pk[instance.pk])
    42 
     41    setattr(instance, attname, value_by_pk[instance.pk])
     42}}}
    4343in_bulk() does not include primary keys for rows that no longer exist. Consequently, if one peer has been deleted, accessing the deferred field on another existing peer can raise KeyError.
    4444
Back to Top