#18407: 500 instead of 404 when unicode in url
----------------------------------------------+----------------------------
Reporter: znotdead | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.4
Severity: Normal | Keywords: urls pk admin
Triage Stage: Unreviewed | unicode
Easy pickings: 0 | Has patch: 0
| UI/UX: 0
----------------------------------------------+----------------------------
Does not provided case when object_id is Unicode[[BR]]
Example:
http://localhost:8000/admin/auth/user/%D1%8B%D0%B2%D0%B0%D1%8B%D0%B2/
Gives error:
{{{
UnicodeEncodeError at /admin/auth/user/ываыв/
'ascii' codec can't encode characters in position 0-4: ordinal not in
range(128)
Request Method: GET
Request URL:
http://localhost:8000/admin/auth/user/%D1%8B%D0%B2%D0%B0%D1%8B%D0%B2/
Django Version: 1.4
Exception Type: UnicodeEncodeError
Exception Value:
'ascii' codec can't encode characters in position 0-4: ordinal not in
range(128)
Exception Location: /media/disk/env/django14/lib/python2.6/site-
packages/django/db/models/fields/__init__.py in to_python, line 528
Python Executable: /media/disk/env/django14/bin/python
Python Version: 2.6.7
}}}
Exception happened on AutoField(Field) to_python method:
{{{
msg = self.error_messages['invalid'] % str(value)
}}}
And so we have 500 but not 404.
{{{
/media/disk/env/django14/lib/python2.6/site-
packages/django/contrib/admin/options.py in get_object
Returns an instance matching the primary key provided.
``None`` is
returned if no match is found (or the object_id failed
validation
against the primary key field).
"""
queryset = self.queryset(request)
model = queryset.model
try:
object_id = model._meta.pk.to_python(object_id)
...
return queryset.get(pk=object_id)
except (model.DoesNotExist, ValidationError):
return None
def get_changelist_form(self, request, **kwargs):
"""
▶ Local vars
/media/disk/env/django14/lib/python2.6/site-
packages/django/db/models/fields/__init__.py in to_python
def to_python(self, value):
if value is None:
return value
try:
return int(value)
except (TypeError, ValueError):
msg = self.error_messages['invalid'] % str(value)
...
raise exceptions.ValidationError(msg)
def validate(self, value, model_instance):
pass
def get_prep_value(self, value):
▼ Local vars
Variable Value
self <django.db.models.fields.AutoField: id>
value u'\u044b\u0432\u0430\u044b\u0432'
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/18407>
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 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.