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/many_to_one | |
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/many_to_one')
-rw-r--r-- | tests/many_to_one/tests.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/tests/many_to_one/tests.py b/tests/many_to_one/tests.py index b8b040eff6..2311834481 100644 --- a/tests/many_to_one/tests.py +++ b/tests/many_to_one/tests.py @@ -738,14 +738,16 @@ class ManyToOneTests(TestCase): self.assertEqual("id", cat.remote_field.get_related_field().name) def test_relation_unsaved(self): - # The <field>_set manager does not join on Null value fields (#17541) Third.objects.create(name="Third 1") Third.objects.create(name="Third 2") th = Third(name="testing") - # The object isn't saved and thus the relation field is null - we won't even - # execute a query in this case. - with self.assertNumQueries(0): - self.assertEqual(th.child_set.count(), 0) + # The object isn't saved and the relation cannot be used. + msg = ( + "'Third' instance needs to have a primary key value before this " + "relationship can be used." + ) + with self.assertRaisesMessage(ValueError, msg): + th.child_set.count() th.save() # Now the model is saved, so we will need to execute a query. with self.assertNumQueries(1): |