Opened 37 hours ago
Last modified 21 minutes ago
#36207 new Bug
refresh_from_db() doesn't refresh ForeignObject relations — at Initial Version
Reported by: | Jacob Walls | Owned by: | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 5.2 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Although it's an internal API ForeignObject
is now quasi-public. When trying it out in a non-composite-pk situation I found that refresh_from_db()
didn't clear out a related ForeignObject.
Here is a rough test using the composite_pk models:
-
tests/composite_pk/test_models.py
diff --git a/tests/composite_pk/test_models.py b/tests/composite_pk/test_models.py index 27157a52ad..fdf58d1621 100644
a b class CompositePKModelsTests(TestCase): 155 155 self.assertEqual(4, token.permission_set.count()) 156 156 self.assertEqual(4, user.permission_set.count()) 157 157 self.assertEqual(4, comment.permission_set.count()) 158 159 def test_refresh_foreign_object(self): 160 self.comment_1.user = self.comment_2.user 161 self.assertEqual(self.comment_1.user, self.comment_2.user) 162 self.comment_1.refresh_from_db() 163 self.assertNotEqual(self.comment_1.user, self.comment_2.user)
====================================================================== FAIL: test_refresh_foreign_object (composite_pk.test_models.CompositePKModelsTests.test_refresh_foreign_object) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/.../django/tests/composite_pk/test_models.py", line 163, in test_refresh_foreign_object self.assertNotEqual(self.comment_1.user, self.comment_2.user) ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AssertionError: <User: User object ((1, 1))> == <User: User object ((1, 1))> ---------------------------------------------------------------------- Ran 1 test in 0.006s FAILED (failures=1)
Note:
See TracTickets
for help on using tickets.