#29318: ValidationError has no attribute `error_list` if message is a dict, but
Field.run_validators() depends on it
-------------------------------+--------------------------------------
     Reporter:  Michael Käufl  |                    Owner:  nobody
         Type:  Bug            |                   Status:  new
    Component:  Core (Other)   |                  Version:  master
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------

Comment (by Simon Charette):

 I think that `Field.run_validators()` should not to handle `dict` based
 `ValidationError` as they should only be used to map concrete fields to
 errors in multi-fields cleaning functions (e.g. `Form.clean()`,
 `Model.clean()`). Since `Field` instances cannot have nested-fields I
 wouldn't expect `dict` to be handled.

 In your `JSONField` subclass example you're using an invalid `key` as your
 field mapping. This `key` doesn't map to any field and raising
 `ValidationError(f'Key {key} not allowed.')` within the field would be
 more appropriate.

 Keep in mind that errors have to be ultimately flattened to a `{field_name
 -> error_list}` map at the form/model level while a different model is
 used for DRF serializers since they have nested fields.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29318#comment:3>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.00d692d1bc5c3e4186a02bc7ae2c60cb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to