[storm] Questions about inserts

Christopher Armstrong radix at twistedmatrix.com
Fri Jun 13 09:56:28 BST 2008


> David Koblas <koblas at ...> writes:
>> I'm finding it a bit tidious to constantly be casting from str(...) to
>> unicode(...) to keep the database happy.  Is there really a best
>> practice for how to have VARCHAR columns that are should be treated as
>> RawStr() for purposes of development?

There is a best practice: It's to never rely on automatic encoding or
decoding of str and unicode objects. On all I/O boundaries (web input
/ output, email input / output, file I/O, etc), you need to explicitly
encode and decode with the appropriate encoding (utf-8, ascii, utf-16,
etc) for the given transport.

If you do end up using automatic encoding and decoding, then your app
will most likely break some time when a user comes along and decides
to enter characters that don't fit in ASCII.

-- 
Christopher Armstrong
International Man of Twistery
http://radix.twistedmatrix.com/
http://twistedmatrix.com/
http://canonical.com/



More information about the storm mailing list