niceban / django-command-extensions

Automatically exported from code.google.com/p/django-command-extensions
MIT License
0 stars 0 forks source link

print_user_for_session will crash on UTF-16 characers #14

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
If the user being printed has unicode characters for their first/last/or
user names, then the command will crash with an encoding error (if the
default DB encoding is not UTF8 or ASCII). This is because it uses the
'print' statement. We should be attempting to safe encode the strings
before printing.

There are other issues out of our control if the user has the wrong locale
or font set for the shell, but that is not our problem. 

Original issue reported on code.google.com by doug.nap...@gmail.com on 3 Jun 2008 at 1:10

GoogleCodeExporter commented 9 years ago
Django in the 1.0 documentation specifies that you should use UTF-8 (or 
UTF-16?) for
your database.

Original comment by v.oostv...@gmail.com on 12 Sep 2008 at 1:58

GoogleCodeExporter commented 9 years ago

Original comment by doug.nap...@gmail.com on 12 Sep 2008 at 2:52

GoogleCodeExporter commented 9 years ago
The point is we should be using the django safe_str() calls and the like to 
convert
the strings before printing. Not sure what to do when the terminal supports the
printing of other charsets, (but I believe the underlying python print 
mechanism will
still crash trying to treat the string as ascii-7).

in short: 
    print Model.field # BAD
    print safe_str(Model.field) # GOOD
    raise Exception(Model.field) # BAD
    raise Exception(safe_str(Model.field) #GOOD

It's a 2 second fix, will try to get to it soon.

Original comment by doug.nap...@gmail.com on 12 Sep 2008 at 2:58

GoogleCodeExporter commented 9 years ago
Otherwise i will do it.

Also we might try and see if we should either change more commands that output 
user
input / unicode input on the cli with a safe_str wrapper or maybe provide our 
own
safe_print in django_extensions.utils

FYI: Some similar/related discussion in ticket:
http://code.google.com/p/django-command-extensions/issues/detail?id=12&can=1

Original comment by v.oostv...@gmail.com on 12 Sep 2008 at 4:35

GoogleCodeExporter commented 9 years ago

Original comment by v.oostv...@gmail.com on 12 Sep 2008 at 4:35