convert_unicode and use_native_unicode parameters for engine_from_config

Issue #1899 resolved
Former user created an issue

I have problems with two config file parameters:

  1. convert_to_unicode - it's not boolean, but boolean or 'force'. So far I cannot use value 'force'.

  2. use_native_unicode - not detected as boolean. String value 'false' in boolean expression evaluates as true. It breaks String bind processor for psycopg2 dialect (probably related to #1792).

location of code: http://www.sqlalchemy.org/trac/browser/lib/sqlalchemy/engine/init.py in _coerce_config(configuration, prefix)

Comments (3)

  1. Mike Bayer repo owner
    • changed milestone to 0.6.4
    • assigned issue to
    • changed component to engine

    Here's a patch, but can't commit til the unit tests are updated:

    diff -r 3d439e180103e3b1aab14094912bb566da2d7f5d lib/sqlalchemy/engine/__init__.py
    --- a/lib/sqlalchemy/engine/__init__.py Mon Aug 30 20:10:03 2010 -0400
    +++ b/lib/sqlalchemy/engine/__init__.py Wed Sep 01 11:23:58 2010 -0400
    @@ -268,14 +268,15 @@
                        for key in configuration
                        if key.startswith(prefix))
         for option, type_ in (
    -        ('convert_unicode', bool),
    +        ('convert_unicode', util.bool_or_str('force')),
             ('pool_timeout', int),
    -        ('echo', bool),
    -        ('echo_pool', bool),
    +        ('echo', util.bool_or_str('debug')),
    +        ('echo_pool', util.bool_or_str('debug')),
             ('pool_recycle', int),
             ('pool_size', int),
             ('max_overflow', int),
             ('pool_threadlocal', bool),
    +        ('use_native_unicode', bool),
         ):
             util.coerce_kw_type(options, option, type_)
         return options
    diff -r 3d439e180103e3b1aab14094912bb566da2d7f5d lib/sqlalchemy/util.py
    --- a/lib/sqlalchemy/util.py    Mon Aug 30 20:10:03 2010 -0400
    +++ b/lib/sqlalchemy/util.py    Wed Sep 01 11:23:58 2010 -0400
    @@ -558,6 +558,18 @@
                 raise ValueError("String is not true/false: %r" % obj)
         return bool(obj)
    
    +def bool_or_str(*text):
    +    """Return a callable that will evaulate a string as 
    +    boolean, or one of a set of "alternate" string values.
    +    
    +    """
    +    def bool_or_value(obj):
    +        if obj in text:
    +            return obj
    +        else:
    +            return asbool(obj)
    +    return bool_or_value
    +    
     def coerce_kw_type(kw, key, type_, flexi_bool=True):
         """If 'key' is present in dict 'kw', coerce its value to type 'type\_' if
         necessary.  If 'flexi_bool' is True, the string '0' is considered false
    
  2. Log in to comment