hi,

i was wondering if it would be better to simply reject unicode data in 
django models. at least until better unicode support 
(http://code.djangoproject.com/wiki/UnicodeInDjango) arrives...

that would mean that django would raise an exception when you try to 
assign unicode text into a text-accepting field. (or at save() time).

the reason?

i've just spent some hours debugging a problem, and now i know that when 
using postgresql, "unsafe" characters like ['] are not quoted if the 
string is unicode. they are quoted when the string is a byte-string.

this only happens with the postgresql backend. it works fine with the 
sqlite3 backend.

further debugging showed, that psycopg is at fault, because it quotes 
byte-string params, but not unicode-string params.

also, take an unicode string, like u"gábor" (my name :-). you can assign 
it into a charfield, and if you save the model using sqlite3, it's going 
to be ok. but if you do it with psycopg, you get a segmentation fault 
(on fedora), or a bus-error (on osx). this is again a problem with psycopg.

of course, it's possible to simply in the django-code explicitly convert 
unicode strings to byte-strings. that would be the second approach. but 
please note, that if we follow the python-behaviour, then the 
auto-conversion should happen using us-ascii. which means we can only 
convert ascii-unicode-text, the rest will have to raise an exception. or 
perhaps use settings.DEFAULT_CHARSET?

so because there are so many possible problems, i think requiring 
byte-strings would be the best approach.

after all, even with the current situation, the ONLY safe way to use 
django is to explicitly convert every string into byte-string when 
putting it into a model.

so, what do you think about such approach?


p.s: of course it's quite possible that i simply overlooked a 
DO_WHAT_GABOR_NEEDS setting in settings.py, so if that's the case, 
please tell me :-)


thanks,
gabor

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to