diff options
author | Albert Defler <alnw@interia.eu> | 2022-01-14 12:44:17 +0000 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-22 09:16:40 +0100 |
commit | 7ba6ebe9149ae38257d70100e8bfbfd0da189862 (patch) | |
tree | 1219f1c985851c59e2904add0ce5a74c3b048ef0 /tests/null_queries | |
parent | b7f263551c64e3f80544892e314ed5b0b22cc7c8 (diff) | |
download | django-7ba6ebe9149ae38257d70100e8bfbfd0da189862.tar.gz |
Fixed #19580 -- Unified behavior of reverse foreign key and many-to-many relations for unsaved instances.
Diffstat (limited to 'tests/null_queries')
-rw-r--r-- | tests/null_queries/tests.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/tests/null_queries/tests.py b/tests/null_queries/tests.py index 4c5c3bbe5c..828c68d921 100644 --- a/tests/null_queries/tests.py +++ b/tests/null_queries/tests.py @@ -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): """ |