#36201: ModelChoiceField/ModelMultipleChoiceField.clean() should catch
ValidationError raised by the queryset operations
--------------------------------------+------------------------------------
Reporter: Tim Graham | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: Forms | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Sarah Boyce):
* stage: Unreviewed => Accepted
Comment:
Thank you! Confirmed this is inconsistently handled. The following test
fails for example:
{{{#!diff
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -74,6 +74,7 @@ from .models import (
WriterProfile,
temp_storage_dir,
test_images,
+ UUIDPK,
)
if test_images:
@@ -2177,6 +2178,16 @@ class ModelMultipleChoiceFieldTests(TestCase):
with self.assertRaises(ValidationError):
f.clean([
c6.id])
+ def test_model_multiple_choice_invalid_pk_value_error_messages(self):
+ uuid_f = forms.ModelMultipleChoiceField(UUIDPK.objects.all())
+ f = forms.ModelMultipleChoiceField(Category.objects.all())
+ for model_multiple_choice_form in [f, uuid_f]:
+ with self.assertRaisesMessage(
+ ValidationError,
+ "“invalid” is not a valid value."
+ ):
+ model_multiple_choice_form.clean(["invalid"])
+
def test_model_multiple_choice_required_false(self):
}}}
--
Ticket URL: <
https://code.djangoproject.com/ticket/36201#comment:1>