#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:  Uncategorized  |        Version:  master
               Severity:  Normal         |       Keywords:
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  0              |
-----------------------------------------+------------------------
 If the message is a dict, `ValidationError` has no attribute `error_list`:
 {{{
 class ValidationError(Exception):

     def __init__(self, message, code=None, params=None):
         # …
         if isinstance(message, dict):  # <----
             self.error_dict = {}
             for field, messages in message.items():
                 if not isinstance(messages, ValidationError):
                     messages = ValidationError(messages)
                 self.error_dict[field] = messages.error_list
         elif isinstance(message, list):
             self.error_list = …
             # …
         else:
             # …
             self.error_list = [self]

 }}}
 See
 -
 https://github.com/django/django/blob/2.0.4/django/core/exceptions.py#L115-L137
 -
 
https://github.com/django/django/blob/c3055242c81812278ebdc93dd109f30d2cbd1610/django/core/exceptions.py#L115-L137
 (current master)

 But `Field.run_validators()` depends on `ValidationError` having an
 attribute `error_list`:

 {{{
 class Field(RegisterLookupMixin):

     def run_validators(self, value):
         # …
         for v in self.validators:
             try:
                 v(value)
             except exceptions.ValidationError as e:
                 if hasattr(e, 'code') and e.code in self.error_messages:
                     e.message = self.error_messages[e.code]
                 errors.extend(e.error_list)  # <----

         # …
 }}}

 See
 -
 
https://github.com/django/django/blob/2.0.4/django/db/models/fields/__init__.py#L553-L567
 -
 
https://github.com/django/django/blob/c3055242c81812278ebdc93dd109f30d2cbd1610/django/db/models/fields/__init__.py#L577-L591
 (current master)

 This leads to an `AttributeError` when using a dict as message when
 raising a `ValidationError` inside a validator.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29318>
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/052.45054980c3813cfcee904ea8f7c5ad83%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to