[Django] #35950: Fix refreshing of related fields when one field is deferred

33 views
Skip to first unread message

Django

unread,
Nov 28, 2024, 7:07:34 AM11/28/24
to django-...@googlegroups.com
#35950: Fix refreshing of related fields when one field is deferred
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: Adam Johnson
Johnson |
Type: Bug | Status: assigned
Component: Database | Version: 5.1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/35950>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 28, 2024, 7:18:18 AM11/28/24
to django-...@googlegroups.com
#35950: Fix refreshing of related fields when one field is deferred
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
| Johnson
Type: Bug | Status: assigned
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam Johnson):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35950#comment:1>

Django

unread,
Nov 28, 2024, 10:37:09 AM11/28/24
to django-...@googlegroups.com
#35950: Fix refreshing of related fields when one field is deferred
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
| Johnson
Type: Bug | Status: closed
Component: Database layer | Version: 5.1
(models, ORM) | Resolution:
Severity: Normal | worksforme
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* resolution: => worksforme
* status: assigned => closed

Comment:

I've not been able to replicate following the instructions on Django 5.1.3
--
Ticket URL: <https://code.djangoproject.com/ticket/35950#comment:2>

Django

unread,
Nov 28, 2024, 10:42:25 AM11/28/24
to django-...@googlegroups.com
#35950: Fix refreshing of related fields when one field is deferred
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
| Johnson
Type: Bug | Status: closed
Component: Database layer | Version: 5.1
(models, ORM) | Resolution:
Severity: Normal | worksforme
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* cc: Giannis Terzopoulos (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/35950#comment:3>

Django

unread,
Nov 28, 2024, 11:19:53 AM11/28/24
to django-...@googlegroups.com
#35950: Fix refreshing of related fields when one field is deferred
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
| Johnson
Type: Bug | Status: new
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* resolution: worksforme =>
* stage: Unreviewed => Accepted
* status: closed => new

Comment:

I managed to reproduce locally with
[https://github.com/django/django/pull/18860/files#diff-
51d1f447d95c1f21d5253801dc116988967499bafa107339257bcb58b2513e42R293 the
the additional test provided in the PR].
--
Ticket URL: <https://code.djangoproject.com/ticket/35950#comment:4>

Django

unread,
Nov 28, 2024, 11:36:59 AM11/28/24
to django-...@googlegroups.com
#35950: Fix refreshing of related fields when one field is deferred
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
| Johnson
Type: Bug | Status: new
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_docs: 0 => 1
* severity: Normal => Release blocker

Comment:

Thank you - bisected to 73df8b54a2fab53bec4c7573cda5ad8c869c2fd8
Adam can you add a release note?
--
Ticket URL: <https://code.djangoproject.com/ticket/35950#comment:5>

Django

unread,
Dec 2, 2024, 3:07:31 AM12/2/24
to django-...@googlegroups.com
#35950: Fix refreshing of related fields when one field is deferred
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
| Johnson
Type: Bug | Status: new
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_docs: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/35950#comment:6>

Django

unread,
Dec 2, 2024, 10:00:40 AM12/2/24
to django-...@googlegroups.com
#35950: Fix refreshing of related fields when one field is deferred
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
| Johnson
Type: Bug | Status: new
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/35950#comment:7>

Django

unread,
Dec 2, 2024, 10:01:56 AM12/2/24
to django-...@googlegroups.com
#35950: Fix refreshing of related fields when one field is deferred
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
| Johnson
Type: Bug | Status: closed
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: new => closed

Comment:

In [changeset:"2f6b096b83c55317c7ceef2d8d5dc3bee33293dc" 2f6b096b]:
{{{#!CommitTicketReference repository=""
revision="2f6b096b83c55317c7ceef2d8d5dc3bee33293dc"
Fixed #35950 -- Restored refreshing of relations when fields deferred.

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

Regression in 73df8b54a2fab53bec4c7573cda5ad8c869c2fd8.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35950#comment:8>

Django

unread,
Dec 2, 2024, 10:06:24 AM12/2/24
to django-...@googlegroups.com
#35950: Fix refreshing of related fields when one field is deferred
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
| Johnson
Type: Bug | Status: closed
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"6e3e7353e00b64c61674ac7e0edc7cee761c9b15" 6e3e7353]:
{{{#!CommitTicketReference repository=""
revision="6e3e7353e00b64c61674ac7e0edc7cee761c9b15"
[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.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35950#comment:9>
Reply all
Reply to author
Forward
0 new messages