Python/Django Writes u'' String To Postgresql (with UTF8 DB) and Munges Entry -


i'm sure i've misconfigured here, can't see is.

in django, i've got model field says this:

short_url_slug = autoslugfield(slugify=short_url_slugify, populate_from=id, blank=false, unique=true) 

south creates migration (seemingly) correctly:

'short_url_slug': ('autoslug.fields.autoslugfield', [], {'unique_with': '()', 'max_length': '50', 'populate_from': 'none', 'blank': 'true'}), 

my postgresql db utf8:

\l  (mydbname)                      | (username) | utf8     | en_us.utf-8 | en_us.utf-8 |  

and have real life unicode character:

u'\xa4' 

but when write db, , try read out, get:

in [3]: this_instance.short_url_slug out[3]: u'o' 

thoughts? suspicion postgresql needs have different character encoding, i'm not sure should (if so) or how it.

edit additional info

select version(), current_setting('standard_conforming_strings') scs;  postgresql 9.2.4 on x86_64-apple-darwin11.4.2, compiled i686-apple-darwin11-llvm-gcc-4.2 (gcc) 4.2.1 (based on apple inc. build 5658) (llvm build 2336.9.00), 64-bit | on  (end)  

python version:

python 2.7.2 (default, oct 11 2012, 20:14:37) 

django version:

in [2]: django.version out[2]: (1, 5, 1, 'final', 0) 

psycopg2:

$ pip freeze | grep psycopg2 psycopg2==2.5 

raw log postgresql:

log:  statement: update [...lots of stuff removed...] "short_url_slug" = 'o' [... rest of stuff ...] 

so, looks it's not getting postgresql. when break @ line in insertion, variable has unicode value.

(pdb) response.short_url_slug u'\xd6' 

(this after assignment in python, before response.save())

more output:

the way detecting unicode getting munged database uniqueness constraint getting violated. can tested on outputting content models (with constraint off):

in [11]: = response.objects.all()  in [12]: all[0].short_url_slug out[12]: u'o'  in [13]: all[4].short_url_slug out[13]: u'o'  in [14]: all[4].short_url_slug == all[0].short_url_slug out[14]: true 

django slugify doesn't support unicode, should use unicode-slugify

(as read in 2 scoops of django http://django.2scoops.org/)


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -