diff options
| author | Carlton Gibson <carlton.gibson@noumenal.es> | 2020-02-18 10:50:19 +0100 |
|---|---|---|
| committer | Carlton Gibson <carlton@noumenal.es> | 2020-02-18 19:54:29 +0100 |
| commit | a34cb5a6d408203f4fbdb364fc9768c026eda224 (patch) | |
| tree | cfaadf39dabf430c9e46d0e07cf937735650b079 /tests | |
| parent | 3bbf9a489afc689eff2f4a0b84af196aa1ef51e7 (diff) | |
Refs #31282 -- Clarified M2O add/remove/set with PK behaviour.
Improved error message for remove() and added tests.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/many_to_one/tests.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/many_to_one/tests.py b/tests/many_to_one/tests.py index d769b206b9..76ef4921dd 100644 --- a/tests/many_to_one/tests.py +++ b/tests/many_to_one/tests.py @@ -733,3 +733,14 @@ class ManyToOneTests(TestCase): child = parent.to_field_children.get() with self.assertNumQueries(0): self.assertIs(child.parent, parent) + + def test_add_remove_set_by_pk_raises(self): + usa = Country.objects.create(name='United States') + chicago = City.objects.create(name='Chicago') + msg = "'City' instance expected, got %s" % chicago.pk + with self.assertRaisesMessage(TypeError, msg): + usa.cities.add(chicago.pk) + with self.assertRaisesMessage(TypeError, msg): + usa.cities.remove(chicago.pk) + with self.assertRaisesMessage(TypeError, msg): + usa.cities.set([chicago.pk]) |
