mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #22808 -- Made ModelMultipleChoiceField validation more robust to invalid data types..
Thanks Mattias Lindvall for the report and inital patch.
This commit is contained in:
committed by
Tim Graham
parent
7579080899
commit
cdc25ac474
@@ -1391,6 +1391,13 @@ class ModelChoiceFieldTests(TestCase):
|
||||
f.clean(None)
|
||||
with self.assertRaises(ValidationError):
|
||||
f.clean(0)
|
||||
|
||||
# Invalid types that require TypeError to be caught (#22808).
|
||||
with self.assertRaises(ValidationError):
|
||||
f.clean([['fail']])
|
||||
with self.assertRaises(ValidationError):
|
||||
f.clean([{'foo': 'bar'}])
|
||||
|
||||
self.assertEqual(f.clean(self.c2.id).name, "It's a test")
|
||||
self.assertEqual(f.clean(self.c3.id).name, 'Third')
|
||||
|
||||
@@ -1495,6 +1502,12 @@ class ModelMultipleChoiceFieldTests(TestCase):
|
||||
with self.assertRaises(ValidationError):
|
||||
f.clean(['fail'])
|
||||
|
||||
# Invalid types that require TypeError to be caught (#22808).
|
||||
with self.assertRaises(ValidationError):
|
||||
f.clean([['fail']])
|
||||
with self.assertRaises(ValidationError):
|
||||
f.clean([{'foo': 'bar'}])
|
||||
|
||||
# Add a Category object *after* the ModelMultipleChoiceField has already been
|
||||
# instantiated. This proves clean() checks the database during clean() rather
|
||||
# than caching it at time of instantiation.
|
||||
|
||||
Reference in New Issue
Block a user