Opened 17 years ago

Closed 17 years ago

#5448 closed (fixed)

Primary key can't be string with unicode characters

Reported by: Maciej Wiśniowski Owned by: Maciej Wiśniowski
Component: Core (Other) Version: dev
Severity: Keywords: unicode primary key pk
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Model defined like:

class Actor(models.Model):

name = models.CharField(max_length=20, primary_key=True)

when trying to save it:

travolta = Actor(name="Zażółć")
travolta.save()

There is UnicodeDecodeError at:
django.db.base.Model -> save function:

File ".../lib/python2.4/site-packages/django/db/models/base.py", line 218, in save

pk_set = pk_val is not None and pk_val != u

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 2: ordinal not in range(128)

fix should use smart_unicode like:
pk_set = pk_val is not None and smart_unicode(pk_val) != u

Attachments (1)

primary_unicode.diff (1.5 KB ) - added by Maciej Wiśniowski 17 years ago.
Patch against revision 6193

Download all attachments as: .zip

Change History (6)

comment:1 by anonymous, 17 years ago

Is there a relationship with ticket:4725 (Quote problem with string primary keys in the admin panel) ?

comment:2 by Maciej Wiśniowski, 17 years ago

I think it is not connected. Here, there is an issue with saving to rdbms and in 4725 the problem is with querying database and quoting

comment:3 by Maciej Wiśniowski, 17 years ago

Owner: changed from nobody to Maciej Wiśniowski
Status: newassigned

by Maciej Wiśniowski, 17 years ago

Attachment: primary_unicode.diff added

Patch against revision 6193

comment:4 by Maciej Wiśniowski, 17 years ago

Has patch: set
Triage Stage: UnreviewedReady for checkin

comment:5 by Jacob, 17 years ago

Resolution: fixed
Status: assignedclosed

(In [6200]) Fixed #5448: you can now use unicode characters in primary keys. Thanks, pigletto.

Note: See TracTickets for help on using tickets.
Back to Top