From 74b67ac97429dbb1cc7c8a12035e1c55de67ad88 Mon Sep 17 00:00:00 2001 From: Kurt Grutzmacher Date: Tue, 11 Jun 2019 10:44:03 -0700 Subject: [PATCH] Use ClauseElement.__str__() instead of str() to obtain statement 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 --- flask_sqlalchemy_caching/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask_sqlalchemy_caching/core.py b/flask_sqlalchemy_caching/core.py index e86b2f7..f53a751 100644 --- a/flask_sqlalchemy_caching/core.py +++ b/flask_sqlalchemy_caching/core.py @@ -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()