this happens when you do this:

class SomeClass(Base):
    # ...

   some_col = Column(Unicode(50))

s = SomeClass(somestring='some value')

and then when you commit "s" to the database, the bytestring is detected and 
the warning emitted.   Note 'some value' is a Python bytestring, not a Unicode 
string, that is:  u'some value'.

Solutions:

1. use unicode strings, u'some value'.

2. turn on u'' everywhere, using "from __future__ import unicode_literals"

3. use a "coercing" unicode type, see the example at 
http://docs.sqlalchemy.org/en/rel_0_8/core/types.html#coercing-encoded-strings-to-unicode

4. turn the warning off: http://docs.python.org/2/library/warnings.html

5. use the Unicode type with convert_unicode=False:   Column(Unicode(50, 
convert_unicode=False)) - since you're using psycopg2, SQLAlchemy doesn't need 
to be involved here and setting this flag will disable the check.



On May 6, 2013, at 4:33 PM, Richard Gerd Kuesters <[email protected]> 
wrote:

> Hi, I'm just pulling this up because it's a little anoying. Everytime I start 
> my application, this warning shows:
> 
> [...]/lib/python2.7/site-packages/sqlalchemy/engine/default.py:471: 
> SAWarning: Unicode type received non-unicode bind param value.
>   processors[key](compiled_params[key])
> 
> I don't know if it's some OS+source+db combination I have in my system or 
> something else. Anyway, some info about:
> SA 0.8.1 with C extensions - from pip
> psycopg2 2.5 (dt dec pq3 ext) - from pip
> Python 2.7.4 (default, Apr 19 2013, 18:28:01) - [GCC 4.7.3] on linux2
> OS: [Ubuntu] Linux rkuesters 3.8-10.dmz.1-liquorix-amd64 #1 ZEN SMP PREEMPT 
> Thu May 2 07:09:55 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
> PostgreSQL 9.1 (9.1.9-1ubuntu1)
> 
> Thanks!
> Richard :)
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to