column.startswith doesn't work with unicode fields

Issue #296 resolved
Former user created an issue
Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/colubrid/debug.py", line 919, in __call__
    result = self.application(environ, start_response)
  File "/home/blackbird/Development/pocoo/trunk/pocoo/application.py", line 172, in __call__
    resp = handler.handle_request(req, **args)
  File "/home/blackbird/Development/pocoo/trunk/pocoo/pkg/core/pages.py", line 396, in handle_request
    hide_internal=True
  File "/home/blackbird/Development/pocoo/trunk/pocoo/pkg/core/user.py", line 44, in get_user_list
    q.append(u.username.startswith(letter))
  File "build/bdist.linux-i686/egg/sqlalchemy/sql.py", line 550, in startswith
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 0: ordinal not in range(128)

Happens when i do the following:

    u = users.c
    r = ctx.engine.execute(meta.select([u.username, u.email,
                                        u.profile, u.last_login,
                                        u.register_date, u.post_count](u.user_id,),
                                        meta.and_(*q),
                                        order_by=[order(order_by)](order(order_by))))

(meta == the sqlalchemy module)

The problem is that the code does the following:

    def startswith(self, other):
        return self._compare('LIKE', str(other) + "%")

And because the unicode data (in my case the german umlaut "ä") doesn't fit into ascii sqlalchemy can't handle that.

Comments (1)

  1. Mike Bayer repo owner

    easy enough, the str() is not really needed since i dont believe ppl should be sending non string-like things to startswith() or endswith(). this is fixed with a unit test in changeset:1848

  2. Log in to comment