﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
4725	Quote problem with string primary keys in the admin panel	jedie	nobody	"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"		closed	contrib.admin	newforms-admin		worksforme	nfa-blocker quote		Accepted	0	0	0	0	0	0
