diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2019-07-23 05:04:06 -0700 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-07-27 12:04:56 +0200 |
| commit | 4122d9d3f1983eea612f236e941d937bd8589a0d (patch) | |
| tree | 8b13542116159590bc5fab124574e6b8038de814 /tests | |
| parent | 619c9a4f49a1f0d9b53a732ae8c5132e32a6ce1c (diff) | |
Refs #28147 -- Fixed setting of OneToOne and Foreign Key fields to None when using attnames.
Regression in 519016e5f25d7c0a040015724f9920581551cab0.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/many_to_one/tests.py | 12 | ||||
| -rw-r--r-- | tests/one_to_one/tests.py | 9 |
2 files changed, 21 insertions, 0 deletions
diff --git a/tests/many_to_one/tests.py b/tests/many_to_one/tests.py index a5215e58d7..e3121a7701 100644 --- a/tests/many_to_one/tests.py +++ b/tests/many_to_one/tests.py @@ -168,6 +168,18 @@ class ManyToOneTests(TestCase): parent.bestchild_id = child2.pk self.assertTrue(Parent.bestchild.is_cached(parent)) + def test_assign_fk_id_none(self): + parent = Parent.objects.create(name='jeff') + child = Child.objects.create(name='frank', parent=parent) + parent.bestchild = child + parent.save() + parent.bestchild_id = None + parent.save() + self.assertIsNone(parent.bestchild_id) + self.assertFalse(Parent.bestchild.is_cached(parent)) + self.assertIsNone(parent.bestchild) + self.assertTrue(Parent.bestchild.is_cached(parent)) + def test_selects(self): self.r.article_set.create(headline="John's second story", pub_date=datetime.date(2005, 7, 29)) self.r2.article_set.create(headline="Paul's story", pub_date=datetime.date(2006, 1, 17)) diff --git a/tests/one_to_one/tests.py b/tests/one_to_one/tests.py index 78b3ff1135..1215cf8001 100644 --- a/tests/one_to_one/tests.py +++ b/tests/one_to_one/tests.py @@ -217,6 +217,15 @@ class OneToOneTests(TestCase): b.place_id = self.p2.pk self.assertTrue(UndergroundBar.place.is_cached(b)) + def test_assign_o2o_id_none(self): + b = UndergroundBar.objects.create(place=self.p1) + b.place_id = None + b.save() + self.assertIsNone(b.place_id) + self.assertFalse(UndergroundBar.place.is_cached(b)) + self.assertIsNone(b.place) + self.assertTrue(UndergroundBar.place.is_cached(b)) + def test_related_object_cache(self): """ Regression test for #6886 (the related-object cache) """ |
