#15126: Misleading error in ModelForm
-----------------------------------------------------------+----------------
Reporter: [email protected] | Owner:
nobody
Status: new | Milestone:
Component: Forms | Version: 1.2
Keywords: modelform fields attributeerror widget subset | Stage:
Unreviewed
Has_patch: 0 |
-----------------------------------------------------------+----------------
Hi,
setting the fields attribute in the Meta-class of a ModelForm to a tuple
with only one value specified (without the trailing ',') results in a
string. After expiriencing hours of bugtracking i mentioned this fact. The
django code in this case doesnt exactly point out, whats causing the
problem, because a string as a fields-attribute value also is an iterable
object, so it iterates over every single character of this string(handling
every charactar as a field) and finaly raises a AttributeError ('ΝοneType'
object has no attribute 'widget') when calling the is_valid() method.
It was unnecessarily complicated to recognize the cause for this
exception. After this i found, that the python-docs
(http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences)
also mention this 'ugly' issuse to be fixed by appending a ','.
Perhaps the django-code should help people saving thier time in this case
and evaluate if the fields-attribute contains a string or a valid tuple.
One solution would be to convert a string to a list or to raise a more
meanigful error. Another approach could be a more explicit hint in the
ModelForm-Documentation(by mentioning the error it would cause not
appending a ',').
--
Ticket URL: <http://code.djangoproject.com/ticket/15126>
Django <http://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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.