﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36207	refresh_from_db() doesn't refresh ForeignObject relations	Jacob Walls		"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.

Here is a rough test using the composite_pk models:
{{{#!diff
diff --git a/tests/composite_pk/test_models.py b/tests/composite_pk/test_models.py
index 27157a52ad..fdf58d1621 100644
--- a/tests/composite_pk/test_models.py
+++ b/tests/composite_pk/test_models.py
@@ -155,3 +155,9 @@ class CompositePKModelsTests(TestCase):
         self.assertEqual(4, token.permission_set.count())
         self.assertEqual(4, user.permission_set.count())
         self.assertEqual(4, comment.permission_set.count())
+
+    def test_refresh_foreign_object(self):
+        self.comment_1.user = self.comment_2.user
+        self.assertEqual(self.comment_1.user, self.comment_2.user)
+        self.comment_1.refresh_from_db()
+        self.assertNotEqual(self.comment_1.user, self.comment_2.user)
}}}
----
{{{#!py
======================================================================
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)
}}}"	Bug	new	Database layer (models, ORM)	5.2	Release blocker				Unreviewed	0	0	0	0	0	0
