#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>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070195226ee6e9-35064b5e-086b-4e1e-8caa-599bc8ecc54f-000000%40eu-central-1.amazonses.com.

Reply via email to