#29698: Model Field _check_choices does not handle some invalid values.
-------------------------------------+-------------------------------------
               Reporter:  fmichea    |          Owner:  fmichea
                   Type:  Bug        |         Status:  assigned
              Component:  Database   |        Version:  master
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Model field checks ensure that the `choices` field contains only pairs of
 (real value, human readable value). To do this it unpacks the values,
 protecting against ValueError (example: not a pair but a three-value
 tuple), however it does not protect against TypeError (example: integer),
 which will look something like this trying to runserver:

 {{{
 Performing system checks...

 Unhandled exception in thread started by <function
 check_errors.<locals>.wrapper at 0x10ee2f8c8>
 Traceback (most recent call last):
   File ".../lib/python3.7/site-packages/django/utils/autoreload.py", line
 225, in wrapper
     fn(*args, **kwargs)
   File ".../lib/python3.7/site-
 packages/django/core/management/commands/runserver.py", line 117, in
 inner_run
     self.check(display_num_errors=True)
   File ".../lib/python3.7/site-packages/django/core/management/base.py",
 line 379, in check
     include_deployment_checks=include_deployment_checks,
   File ".../lib/python3.7/site-packages/django/core/management/base.py",
 line 366, in _run_checks
     return checks.run_checks(**kwargs)
   File ".../lib/python3.7/site-packages/django/core/checks/registry.py",
 line 71, in run_checks
     new_errors = check(app_configs=app_configs)
   File ".../lib/python3.7/site-
 packages/django/core/checks/model_checks.py", line 27, in check_all_models
     errors.extend(model.check(**kwargs))
   File ".../lib/python3.7/site-packages/django/db/models/base.py", line
 1183, in check
     *cls._check_fields(**kwargs),
   File ".../lib/python3.7/site-packages/django/db/models/base.py", line
 1261, in _check_fields
     errors.extend(field.check(**kwargs))
   File ".../lib/python3.7/site-
 packages/django/db/models/fields/__init__.py", line 1770, in check
     *super().check(**kwargs),
   File ".../lib/python3.7/site-
 packages/django/db/models/fields/__init__.py", line 203, in check
     *self._check_choices(),
   File ".../lib/python3.7/site-
 packages/django/db/models/fields/__init__.py", line 262, in _check_choices
     group_name, group_choices = choices_group
 TypeError: cannot unpack non-iterable int object
 }}}

 Pull request coming right up.

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

Reply via email to