diff options
| author | Mariana <mmariana.pereira.20@gmail.com> | 2023-07-26 23:58:58 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-08-09 06:59:40 +0200 |
| commit | e02fc588893485e5f5e509cdb67c63d8e1a45b31 (patch) | |
| tree | 30de5cf24d654b6d807096474548e0162e71ad43 /tests | |
| parent | aa3cb3f37265be37d892e2b391ff023e9caee2a4 (diff) | |
Fixed #34586 -- Made QuerySet.create() raise ValueError for reverse one-to-many relations.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/one_to_one/tests.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/one_to_one/tests.py b/tests/one_to_one/tests.py index 3c92445af6..65efee6074 100644 --- a/tests/one_to_one/tests.py +++ b/tests/one_to_one/tests.py @@ -524,6 +524,29 @@ class OneToOneTests(TestCase): Director._meta.base_manager_name = None Director._meta._expire_cache() + def test_create_reverse_o2o_error(self): + msg = "The following fields do not exist in this model: restaurant" + with self.assertRaisesMessage(ValueError, msg): + Place.objects.create(restaurant=self.r1) + + def test_get_or_create_reverse_o2o_error(self): + msg = "The following fields do not exist in this model: restaurant" + r2 = Restaurant.objects.create( + place=self.p2, serves_hot_dogs=True, serves_pizza=False + ) + with self.assertRaisesMessage(ValueError, msg): + Place.objects.get_or_create(name="nonexistent", defaults={"restaurant": r2}) + + def test_update_or_create_reverse_o2o_error(self): + msg = "The following fields do not exist in this model: restaurant" + r2 = Restaurant.objects.create( + place=self.p2, serves_hot_dogs=True, serves_pizza=False + ) + with self.assertRaisesMessage(ValueError, msg): + Place.objects.update_or_create( + name="nonexistent", defaults={"restaurant": r2} + ) + def test_hasattr_related_object(self): # The exception raised on attribute access when a related object # doesn't exist should be an instance of a subclass of `AttributeError` |
