#36344: Accessing a related field after using defer() or only() unexpectedly
overwrites unsaved state on model instances
-------------------------------------+-------------------------------------
Reporter: Erick | Owner: (none)
Type: Uncategorized | Status: closed
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):
* resolution: => invalid
* status: new => closed
Comment:
I cannot reproduce against `main` or 5.2 (which you reported the issue
against) with
{{{#!diff
diff --git a/tests/defer/tests.py b/tests/defer/tests.py
index 989b5c63d7..1b38f2b5d3 100644
--- a/tests/defer/tests.py
+++ b/tests/defer/tests.py
@@ -184,6 +184,18 @@ def test_defer_fk_attname(self):
with self.assertNumQueries(1):
self.assertEqual(primary.related_id, self.p1.related_id)
+ def test_related_fetching(self):
+ Primary.objects.create(
+ name="foo",
+ value="bar",
+ related=Secondary.objects.create(first="first",
second="second"),
+ )
+ primary = Primary.objects.only("name").first()
+ primary.value = "ef"
+ self.assertEqual(primary.value, "ef")
+ primary.related
+ self.assertEqual(primary.value, "ef")
+
class BigChildDeferTests(AssertionMixin, TestCase):
@classmethod
}}}
At first I thought you ran into #35950 (which was fixed in 5.1.4) but I
can't reproduce against 5.1.3 either.
I'm afraid you might have omitted some details here.
--
Ticket URL: <https://code.djangoproject.com/ticket/36344#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/010701965b00dc94-78f75d59-e0e7-4549-ada2-879ad785e5e7-000000%40eu-central-1.amazonses.com.