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:
committed by
Mariusz Felisiak
parent
b7f263551c
commit
7ba6ebe914
@@ -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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user