pallets-eco / flask-debugtoolbar

A toolbar overlay for debugging Flask applications
https://flask-debugtoolbar.readthedocs.io
BSD 3-Clause "New" or "Revised" License
953 stars 146 forks source link

Error when sqlalchemy query has non-ascii characters #55

Closed maxneust closed 10 years ago

maxneust commented 11 years ago

Happens because in the panel from sqlalchemy.py, the template is being rendered with the query as str type instead of unicode, and according to jinja2's documentation:

Unicode

Jinja2 is using Unicode internally which means that you have to pass Unicode objects to the render function or bytestrings that only consist of ASCII characters. Additionally newlines are normalized to one end of line sequence which is per default UNIX style (\n).

Python 2.x supports two ways of representing string objects. One is the str type and the other is the unicode type, both of which extend a type called basestring. Unfortunately the default is str which should not be used to store text based information unless only ASCII characters are used. With Python 2.6 it is possible to make unicode the default on a per module level and with Python 3 it will be the default.

Source:

for query in queries:
    data.append({
        'duration': query.duration,
        'sql': format_sql(query.statement, query.parameters),
        'signed_query': dump_query(query.statement, query.parameters),
        'context_long': query.context,
        'context': format_fname(query.context)
    })
return self.render('panels/sqlalchemy.html', { 'queries': data})

Should be:

for query in queries:
    data.append({
        'duration': query.duration,
        'sql': unicode(format_sql(query.statement, query.parameters), 'utf-8'),
        'signed_query': dump_query(query.statement, query.parameters),
        'context_long': query.context,
        'context': format_fname(query.context)
    })
return self.render('panels/sqlalchemy.html', { 'queries': data})
jacobsvante commented 10 years ago

Might #66 fix this for you?