Opened 12 years ago

Closed 11 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


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/" in get_response
  72. response = middleware_method(request, callback, callback_args, callback_kwargs)
File "./PyLucid/middlewares/" in process_view
  45. response = view_func(request, *view_args, **view_kwargs)
File "./django/contrib/admin/views/" in _checklogin
  55. return view_func(request, *args, **kwargs)
File "./django/views/decorators/" in _wrapped_view_func
  39. response = view_func(request, *args, **kwargs)
File "./django/contrib/admin/views/" in change_stage
  324. manipulator = model.ChangeManipulator(object_id)
File "./django/db/models/" in __init__
  261. self.original_object = self.manager.get(pk=obj_key)
File "./django/db/models/" in get
  73. return self.get_query_set().get(*args, **kwargs)
File "./django/db/models/" in get
  258. obj_list = list(clone)
File "./django/db/models/" in __iter__
  111. return iter(self._get_data())
File "./django/db/models/" in _get_data
  478. self._result_cache = list(self.iterator())
File "./django/db/models/" in iterator
  186. cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params)
File "./django/db/backends/" in execute
  23. 'sql': smart_unicode(sql) % convert_args(params),
File "./django/db/backends/" in convert_args
  50. return tuple([to_unicode(val) for val in args])
File "./django/db/backends/" in
  48. to_unicode = lambda s: force_unicode(s, strings_only=True)
File "./django/utils/" 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 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:

Change History (3)

comment:1 Changed 12 years ago by Simon G <dev@…>

Triage Stage: UnreviewedAccepted
Version: SVNnewforms-admin

comment:2 Changed 12 years ago by Brian Rosner

Keywords: nfa-blocker added

This should be fixed before the merge of newforms-admin into trunk. Marking as a blocker.

comment:3 Changed 11 years ago by tlpinney

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top