UnicodeEncodeError when validating forms with non-ascii field names
|Reported by:||alanjds||Owned by:||unbracketed|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
I am creating forms dynamically, so users can type field names.
Django is raising UnicodeEncodeError when some field name has a non-ascii name. Is simple not acceptable to constrain users to ASCII only.
class UtilizacaoForm(forms.Form): pass ut = UtilizacaoForm() ut.fields[u'Diâmetro'] = forms.CharField(max_length=3) ut.is_valid() File "django/forms/forms.py" in is_valid 120. return self.is_bound and not bool(self.errors) File "django/forms/forms.py" in _get_errors 111. self.full_clean() File "django/forms/forms.py" in full_clean 242. if hasattr(self, 'clean_%s' % name): Exception Type: UnicodeEncodeError at /novakoski/modelos/detalhe/1/ Exception Value: ('ascii', u'clean_Di\xe2metro', 8, 9, 'ordinal not in range(128)')
Occurs because hasattr(obj, str) can't handle non-ascii at str, before preparing to call clean_fieldname.
Original traceback paste: http://dpaste.com/hold/147583/
Quick fix added.
Change History (6)
Changed 6 years ago by alanjds
comment:1 Changed 6 years ago by alanjds
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Summary changed from UnicodeEncodeError when validating forms with non-ascii names to UnicodeEncodeError when validating forms with non-ascii field names
comment:2 Changed 6 years ago by unbracketed
- Owner changed from nobody to unbracketed
- Status changed from new to assigned
comment:3 Changed 6 years ago by unbracketed
- Patch needs improvement set
- Triage Stage changed from Unreviewed to Accepted