Changes between Initial Version and Version 1 of Ticket #36207
- Timestamp:
- Feb 21, 2025, 4:32:46 PM (21 hours ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #36207 – Description
initial v1 1 1 Although it's an internal API `ForeignObject` is now [https://docs.djangoproject.com/en/5.2/topics/composite-primary-key/#composite-primary-keys-and-relations 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. 2 2 3 Here is a rough test using the composite_pk models :3 Here is a rough test using the composite_pk models (EDIT: prior version of test wasn't demonstrating anything): 4 4 {{{#!diff 5 5 diff --git a/tests/composite_pk/test_models.py b/tests/composite_pk/test_models.py 6 index 27157a52ad.. fdf58d16211006446 index 27157a52ad..7cd97a31a9 100644 7 7 --- a/tests/composite_pk/test_models.py 8 8 +++ b/tests/composite_pk/test_models.py 9 @@ -155,3 +155, 9@@ class CompositePKModelsTests(TestCase):9 @@ -155,3 +155,8 @@ class CompositePKModelsTests(TestCase): 10 10 self.assertEqual(4, token.permission_set.count()) 11 11 self.assertEqual(4, user.permission_set.count()) … … 13 13 + 14 14 + def test_refresh_foreign_object(self): 15 + self.comment_1.user = self.comment_2.user 16 + self.assertEqual(self.comment_1.user, self.comment_2.user) 15 + self.comment_1.user = None 17 16 + self.comment_1.refresh_from_db() 18 + self.assert NotEqual(self.comment_1.user, self.comment_2.user)17 + self.assertEqual(self.comment_1.user, self.user_1) 19 18 }}} 20 19 ---- 21 20 {{{#!py 21 E 22 22 ====================================================================== 23 FAIL: test_refresh_foreign_object (composite_pk.test_models.CompositePKModelsTests.test_refresh_foreign_object)23 ERROR: test_refresh_foreign_object (composite_pk.test_models.CompositePKModelsTests.test_refresh_foreign_object) 24 24 ---------------------------------------------------------------------- 25 25 Traceback (most recent call last): 26 File "/Users/.../django/tests/composite_pk/test_models.py", line 163, in test_refresh_foreign_object 27 self.assertNotEqual(self.comment_1.user, self.comment_2.user) 28 ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 29 AssertionError: <User: User object ((1, 1))> == <User: User object ((1, 1))> 26 File "/Users/.../django/tests/composite_pk/test_models.py", line 161, in test_refresh_foreign_object 27 self.comment_1.refresh_from_db() 28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ 29 File "/Users/.../py313/lib/python3.13/site-packages/django/db/models/base.py", line 737, in refresh_from_db 30 db_instance = db_instance_qs.get() 31 File "/Users/.../py313/lib/python3.13/site-packages/django/db/models/query.py", line 633, in get 32 raise self.model.DoesNotExist( 33 "%s matching query does not exist." % self.model._meta.object_name 34 ) 35 composite_pk.models.tenant.Comment.DoesNotExist: Comment matching query does not exist. 30 36 31 37 ---------------------------------------------------------------------- 32 Ran 1 test in 0.00 6s38 Ran 1 test in 0.008s 33 39 34 FAILED ( failures=1)40 FAILED (errors=1) 35 41 }}}