#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 , 11 months ago
| Has patch: | set |
|---|
comment:2 by , 11 months ago
| Resolution: | → worksforme |
|---|---|
| Status: | assigned → closed |
comment:3 by , 11 months ago
| Cc: | added |
|---|
comment:4 by , 11 months ago
| Resolution: | worksforme |
|---|---|
| Status: | closed → new |
| Triage Stage: | Unreviewed → Accepted |
I managed to reproduce locally with the the additional test provided in the PR.
Version 0, edited 11 months ago by (next)
comment:5 by , 11 months ago
| Needs documentation: | set |
|---|---|
| Severity: | Normal → Release blocker |
Thank you - bisected to 73df8b54a2fab53bec4c7573cda5ad8c869c2fd8
Adam can you add a release note?
comment:6 by , 11 months ago
| Needs documentation: | unset |
|---|
comment:7 by , 11 months ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Note:
See TracTickets
for help on using tickets.
I've not been able to replicate following the instructions on Django 5.1.3