Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when sqlalchemy query has non-ascii characters #55

Closed
maxneust opened this issue Aug 9, 2013 · 1 comment
Closed

Error when sqlalchemy query has non-ascii characters #55

maxneust opened this issue Aug 9, 2013 · 1 comment

Comments

@maxneust
Copy link

maxneust commented Aug 9, 2013

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
Copy link

Might #66 fix this for you?

@mgood mgood closed this as completed in 10c0388 Dec 4, 2014
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants