mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #25715 -- Fixed Model.refresh_from_db() with ForeignKey w/on_delete=SET_NULL.
This commit is contained in:
@@ -765,6 +765,17 @@ class ModelRefreshTests(TestCase):
|
||||
self.assertEqual(a2.pub_date, pub_date)
|
||||
self.assertEqual(a2._state.db, "default")
|
||||
|
||||
def test_refresh_fk_on_delete_set_null(self):
|
||||
a = Article.objects.create(
|
||||
headline='Parrot programs in Python',
|
||||
pub_date=datetime(2005, 7, 28),
|
||||
)
|
||||
s1 = SelfRef.objects.create(article=a)
|
||||
a.delete()
|
||||
s1.refresh_from_db()
|
||||
self.assertIsNone(s1.article_id)
|
||||
self.assertIsNone(s1.article)
|
||||
|
||||
def test_refresh_no_fields(self):
|
||||
a = Article.objects.create(pub_date=self._truncate_ms(datetime.now()))
|
||||
with self.assertNumQueries(0):
|
||||
|
||||
Reference in New Issue
Block a user