Code

Opened 7 years ago

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

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 pigletto 7 years ago.
Patch against revision 6193

Download all attachments as: .zip

Change History (6)

comment:1 Changed 7 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 7 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 7 years ago by pigletto

  • Owner changed from nobody to pigletto
  • Status changed from new to assigned

Changed 7 years ago by pigletto

Patch against revision 6193

comment:4 Changed 7 years ago by pigletto

  • Has patch set
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:5 Changed 7 years ago by jacob

  • Resolution set to fixed
  • Status changed from assigned to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.