Opened 18 years ago
Closed 18 years ago
#4725 closed (worksforme)
Quote problem with string primary keys in the admin panel
| Reported by: | jedie | Owned by: | nobody |
|---|---|---|---|
| Component: | contrib.admin | Version: | newforms-admin |
| Severity: | Keywords: | nfa-blocker quote | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I have a table with a CharField primary key:
class PagesInternal(models.Model):
name = models.CharField(primary_key=True, maxlength=150)
...
I get a error, if i edit a entry (with pk='page_admin.edit_page') with the django admin panel:
Traceback (most recent call last):
File "./django/core/handlers/base.py" in get_response
72. response = middleware_method(request, callback, callback_args, callback_kwargs)
File "./PyLucid/middlewares/pagestats.py" in process_view
45. response = view_func(request, *view_args, **view_kwargs)
File "./django/contrib/admin/views/decorators.py" in _checklogin
55. return view_func(request, *args, **kwargs)
File "./django/views/decorators/cache.py" in _wrapped_view_func
39. response = view_func(request, *args, **kwargs)
File "./django/contrib/admin/views/main.py" in change_stage
324. manipulator = model.ChangeManipulator(object_id)
File "./django/db/models/manipulators.py" in __init__
261. self.original_object = self.manager.get(pk=obj_key)
File "./django/db/models/manager.py" in get
73. return self.get_query_set().get(*args, **kwargs)
File "./django/db/models/query.py" in get
258. obj_list = list(clone)
File "./django/db/models/query.py" in __iter__
111. return iter(self._get_data())
File "./django/db/models/query.py" in _get_data
478. self._result_cache = list(self.iterator())
File "./django/db/models/query.py" in iterator
186. cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params)
File "./django/db/backends/util.py" in execute
23. 'sql': smart_unicode(sql) % convert_args(params),
File "./django/db/backends/util.py" in convert_args
50. return tuple([to_unicode(val) for val in args])
File "./django/db/backends/util.py" in
48. to_unicode = lambda s: force_unicode(s, strings_only=True)
File "./django/utils/encoding.py" in force_unicode
42. s = unicode(s, encoding, errors)
UnicodeDecodeError at /_admin/PyLucid/pagesinternal/page_admin.edit_page/
'utf8' codec can't decode byte 0xad in position 4: unexpected code byte
The problem is not directly this UnicodeDecodeError! It's a problem with the quote()/unquote() routines in django.contrib.admin.views.main.py and the character combination "_ad" (a valid hex digits).
The real problem is: The primary key string runs through unquote(), but it doesn't run through quote() previously! Probably the error is in change_stage(). I don't known why quote() is not used.
btw. I use a work-a-round and replace all underscores to spaces :-/
A discuss exists here:
http://groups.google.com/group/django-developers/browse_thread/thread/e1ed7f81e54e724a/aacfe0f3d49217c9
Change History (3)
comment:1 by , 18 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|---|
| Version: | SVN → newforms-admin |
comment:2 by , 18 years ago
| Keywords: | nfa-blocker added |
|---|
comment:3 by , 18 years ago
| Resolution: | → worksforme |
|---|---|
| Status: | new → closed |
This should be fixed before the merge of newforms-admin into trunk. Marking as a blocker.