Opened 9 years ago

Closed 9 years ago

#5448 closed (fixed)

Primary key can't be string with unicode characters

Reported by: pigletto Owned by: pigletto
Component: Core (Other) Version: master
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: UI/UX:


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żółć")

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

File ".../lib/python2.4/site-packages/django/db/models/", 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 pigletto 9 years ago.
Patch against revision 6193

Download all attachments as: .zip

Change History (6)

comment:1 Changed 9 years ago by anonymous

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

comment:2 Changed 9 years ago by pigletto

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 Changed 9 years ago by pigletto

Owner: changed from nobody to pigletto
Status: newassigned

Changed 9 years ago by pigletto

Attachment: primary_unicode.diff added

Patch against revision 6193

comment:4 Changed 9 years ago by pigletto

Has patch: set
Triage Stage: UnreviewedReady for checkin

comment:5 Changed 9 years ago by Jacob

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