Skip to content

Commit

Permalink
Use ClauseElement.__str__() instead of str() to obtain statement
Browse files Browse the repository at this point in the history
When an field value is a unicode string, the use of str() in python 2.x
will cause the str() call to fail. Python 3.x does not have a unicode()
function, however SQLAlchemy does have __str__() which will do
encoding between py2 and py3.

https://github.com/sqlalchemy/sqlalchemy/blob/master/lib/sqlalchemy/sql/elements.py#L489
  • Loading branch information
grutz authored and bbelyeu committed Jun 18, 2019
1 parent 66edd1e commit 74b67ac
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion flask_sqlalchemy_caching/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def key_from_query(self, qualifier=None):
particular Query, then combining that with the bound parameter values.
"""
stmt = self.with_labels().statement
key = str(stmt.compile(compile_kwargs={'literal_binds': True}))
key = stmt.compile(compile_kwargs={'literal_binds': True}).__str__()
return md5(key.encode('utf8')).hexdigest()


Expand Down

0 comments on commit 74b67ac

Please sign in to comment.