#24271 closed Bug (invalid)
Error message for fields.E005 does not specify that both 'actual value', 'human readable name' must be strings/'Actual Value should be able to be a non-string
Reported by: | AncientSwordRage | Owned by: | Matthew Basanta |
---|---|---|---|
Component: | Core (Other) | Version: | 1.7 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
There is some code that checks your choice of choices is valid. At one point it checks this:
isinstance(choice, six.string_types)
Which checks that BOTH parts of the 2-tuple are strings (e.g. human readable). But the error message just says:
"'choices' must be an iterable containing (actual value, human readable name) tuples."
Which does not specify type in anyway, (e.g it doesn't say they must be some kind of string).
Either the error should say that both parts must be strings (and thus block some fields from using them e.g. integer fields), or only the second element should be checked, thusly:
>>> choices = ( ... (1, 'Primary'), (2, 'Secondary'), (3, 'Tertiary') ... ) >>> any(isinstance(choice, six.string_types) for choice in choices) False >>> any(isinstance(choice[1], six.string_types) for choice in choices) True >>>
Change History (3)
comment:1 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:3 by , 10 years ago
Resolution: | fixed → invalid |
---|
Whoops, I mean 'invalid', not 'fixed'. (I can't edit that, can I?)
Turns out to be a bug in the user's code, not in Django: http://stackoverflow.com/questions/28304776/are-numerically-keyed-choices-no-longer-possible-in-django-1-7