1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #19580 -- Unified behavior of reverse foreign key and many-to-many relations for unsaved instances.

This commit is contained in:
Albert Defler
2022-01-14 12:44:17 +00:00
committed by Mariusz Felisiak
parent b7f263551c
commit 7ba6ebe914
5 changed files with 80 additions and 8 deletions

View File

@@ -44,9 +44,14 @@ class NullQueriesTests(TestCase):
with self.assertRaisesMessage(ValueError, "Cannot use None as a query value"):
Choice.objects.filter(id__gt=None)
# Related managers use __exact=None implicitly if the object hasn't been saved.
p2 = Poll(question="How?")
self.assertEqual(repr(p2.choice_set.all()), "<QuerySet []>")
def test_unsaved(self):
poll = Poll(question="How?")
msg = (
"'Poll' instance needs to have a primary key value before this "
"relationship can be used."
)
with self.assertRaisesMessage(ValueError, msg):
poll.choice_set.all()
def test_reverse_relations(self):
"""