mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
[1.8.x] Fixed #24418 -- Prevented crash in refresh_from_db with null fk
Thanks Johannes Lerch for the report, Tim Graham for the test case,
and Simon Charette for the review.
Backport of 5cf96b49e4 from master.
This commit is contained in:
@@ -736,6 +736,13 @@ class ModelRefreshTests(TestCase):
|
||||
self.assertFalse(hasattr(s3_copy.selfref, 'touched'))
|
||||
self.assertEqual(s3_copy.selfref, s2)
|
||||
|
||||
def test_refresh_null_fk(self):
|
||||
s1 = SelfRef.objects.create()
|
||||
s2 = SelfRef.objects.create(selfref=s1)
|
||||
s2.selfref = None
|
||||
s2.refresh_from_db()
|
||||
self.assertEqual(s2.selfref, s1)
|
||||
|
||||
def test_refresh_unsaved(self):
|
||||
pub_date = self._truncate_ms(datetime.now())
|
||||
a = Article.objects.create(pub_date=pub_date)
|
||||
|
||||
Reference in New Issue
Block a user