Re: [Django] #36207: refresh_from_db() doesn't clear cached ForeignObject relations

14 views
Skip to first unread message

Django

unread,
Mar 9, 2025, 11:53:06 AM3/9/25
to django-...@googlegroups.com
#36207: refresh_from_db() doesn't clear cached ForeignObject relations
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Gregory
| Mariani
Type: Bug | Status: assigned
Component: Database layer | Version: 5.2
(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 Jacob Walls):

* needs_better_patch: 1 => 0

Comment:

I opened a [https://github.com/django/django/pull/19245 PR] with my
proposed alternative.
--
Ticket URL: <https://code.djangoproject.com/ticket/36207#comment:15>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 26, 2025, 5:46:01 AM4/26/25
to django-...@googlegroups.com
#36207: refresh_from_db() doesn't clear cached ForeignObject relations
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Jacob
| Walls
Type: Bug | Status: assigned
Component: Database layer | Version: 5.2
(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 Jacob Walls):

* owner: Gregory Mariani => Jacob Walls

Comment:

Thanks Gregory for advancing the investigation here. Since the first PR is
now closed, I'm going to set myself in the owner field. Eager to hear any
feedback you might have for me.
--
Ticket URL: <https://code.djangoproject.com/ticket/36207#comment:16>

Django

unread,
Apr 26, 2025, 1:09:28 PM4/26/25
to django-...@googlegroups.com
#36207: refresh_from_db() doesn't clear cached ForeignObject relations
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Jacob
| Walls
Type: Bug | Status: assigned
Component: Database layer | Version: 5.2
(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
-------------------------------------+-------------------------------------
Comment (by moshe nahmias):

The test passes and actually test the behavior (so it fails on master but
pass on the branch PR).
The code is similar to the surrounding code and looks good
--
Ticket URL: <https://code.djangoproject.com/ticket/36207#comment:17>

Django

unread,
Apr 26, 2025, 1:10:43 PM4/26/25
to django-...@googlegroups.com
#36207: refresh_from_db() doesn't clear cached ForeignObject relations
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Jacob
| Walls
Type: Bug | Status: assigned
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Normal | 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 moshe nahmias):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/36207#comment:18>

Django

unread,
Apr 27, 2025, 2:05:02 AM4/27/25
to django-...@googlegroups.com
#36207: refresh_from_db() doesn't clear cached ForeignObject relations
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Jacob
| Walls
Type: Bug | Status: assigned
Component: Database layer | Version: 5.2
(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 Clifford Gama):

* stage: Ready for checkin => Accepted

--
Ticket URL: <https://code.djangoproject.com/ticket/36207#comment:19>

Django

unread,
May 6, 2025, 8:49:47 AM5/6/25
to django-...@googlegroups.com
#36207: refresh_from_db() doesn't clear cached ForeignObject relations
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Jacob
| Walls
Type: Bug | Status: assigned
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Normal | 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 Clifford Gama):

* stage: Accepted => Ready for checkin

Comment:

Patch LGTM

The only remaining consideration is whether adding an entry to
`FORWARD_PROPERTIES` without adding a corresponding test—despite limited
test coverage for this set—is acceptable. Since:
1. The risk appears low (no tests fail without it, but stale cache could
theoretically occur).
2. Testing this edge case robustly would likely require invasive model
mutations post-setup.
3. Field-related entries in `FORWARD_PROPERTIES` are untested (You can
remove all but one of them without seeing any test failures.
Leaving this to the merger’s discretion.
--
Ticket URL: <https://code.djangoproject.com/ticket/36207#comment:20>

Django

unread,
May 9, 2025, 8:01:14 AM5/9/25
to django-...@googlegroups.com
#36207: refresh_from_db() doesn't clear cached ForeignObject relations
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Jacob
| Walls
Type: Bug | Status: closed
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Normal | 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: assigned => closed

Comment:

In [changeset:"69ab6e5896ff1a6d9e7ab8a28e75c28d3d7d65f4" 69ab6e5]:
{{{#!CommitTicketReference repository=""
revision="69ab6e5896ff1a6d9e7ab8a28e75c28d3d7d65f4"
Fixed #36207 -- Cleared cached ForeignObject relations via
refresh_from_db().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36207#comment:21>
Reply all
Reply to author
Forward
0 new messages