Opened 6 weeks ago

Closed 6 weeks ago

Last modified 6 weeks ago

#35950 closed Bug (fixed)

Fix refreshing of related fields when one field is deferred

Reported by: Adam Johnson Owned by: Adam Johnson
Component: Database layer (models, ORM) Version: 5.1
Severity: Release blocker Keywords:
Cc: Giannis Terzopoulos Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In #35044, we fixed the issue where loading a deferred field would clear related objects.

But it left a bug where refreshing all fields explicitly with refresh_from_db() would no longer clear related objects *if* the model instance had any deferred fields.

This would work on Django 5.0 but is broken on 5.1:

book = Book.objects.defer('title').get(pk=1)
assert book.author is not None  # fetch related object
Author.objects.all().delete()

book.refresh_from_db()
assert book.author is None  # should have been reset by the refresh

Fix incoming.

Change History (9)

comment:1 by Adam Johnson, 6 weeks ago

Has patch: set

comment:2 by Sarah Boyce, 6 weeks ago

Resolution: worksforme
Status: assignedclosed

I've not been able to replicate following the instructions on Django 5.1.3

comment:3 by Sarah Boyce, 6 weeks ago

Cc: Giannis Terzopoulos added

comment:4 by Simon Charette, 6 weeks ago

Resolution: worksforme
Status: closednew
Triage Stage: UnreviewedAccepted

I managed to reproduce locally with the the additional test provided in the PR.

Version 0, edited 6 weeks ago by Simon Charette (next)

comment:5 by Sarah Boyce, 6 weeks ago

Needs documentation: set
Severity: NormalRelease blocker

Thank you - bisected to 73df8b54a2fab53bec4c7573cda5ad8c869c2fd8
Adam can you add a release note?

comment:6 by Sarah Boyce, 6 weeks ago

Needs documentation: unset

comment:7 by Sarah Boyce, 6 weeks ago

Triage Stage: AcceptedReady for checkin

comment:8 by Sarah Boyce <42296566+sarahboyce@…>, 6 weeks ago

Resolution: fixed
Status: newclosed

In 2f6b096b:

Fixed #35950 -- Restored refreshing of relations when fields deferred.

Thank you to Simon Charette and Sarah Boyce for the review.

Regression in 73df8b54a2fab53bec4c7573cda5ad8c869c2fd8.

comment:9 by Sarah Boyce <42296566+sarahboyce@…>, 6 weeks ago

In 6e3e7353:

[5.1.x] Fixed #35950 -- Restored refreshing of relations when fields deferred.

Thank you to Simon Charette and Sarah Boyce for the review.

Regression in 73df8b54a2fab53bec4c7573cda5ad8c869c2fd8.

Backport of 2f6b096b83c55317c7ceef2d8d5dc3bee33293dc from main.

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