superset: Dashboard filter error - 'ascii' codec can't encode character

Make sure these boxes are checked before submitting your issue - thank you!

  • I have checked the superset logs for python stacktraces and included it here as text if any
  • I have reproduced the issue with at least the latest released version of superset
  • I have checked the issue tracker for the same issue and I haven’t found one similar

Superset version

{“GIT_SHA”: “”, “version”: “0.17.2”}

Expected results

Filtering the table without errors

Actual results

'ascii' codec can't encode character u'\u0406' in position 1512: ordinal not in range(128)

in terminal

2017-03-31 13:40:17,476:ERROR:root:'ascii' codec can't encode character u'\u0406' in position 1512: ordinal not in range(128)
Traceback (most recent call last):
  File "/data/work/virtualenvs/superset/lib/python2.7/site-packages/superset/viz.py", line 234, in get_payload
    df = self.get_df()
  File "/data/work/virtualenvs/superset/lib/python2.7/site-packages/superset/viz.py", line 78, in get_df
    self.results = self.datasource.query(query_obj)
  File "/data/work/virtualenvs/superset/lib/python2.7/site-packages/superset/connectors/sqla/models.py", line 536, in query
    sql = self.get_query_str(**query_obj)
  File "/data/work/virtualenvs/superset/lib/python2.7/site-packages/superset/connectors/sqla/models.py", line 318, in get_query_str
    compile_kwargs={"literal_binds": True}
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0406' in position 1512: ordinal not in range(128)
2017-03-31 13:40:17,479:INFO:root:Caching for the next 86400 seconds

Steps to reproduce

default

After selecting a filter

default

Thank you

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 16 (7 by maintainers)

Most upvoted comments

This should fix the issue and doesn’t break tests here:

diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py
index 903182de..1a2bc37e 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -3,6 +3,7 @@ import logging
 import sqlparse
 
 import pandas as pd
+import six
 
 from sqlalchemy import (
     Column, Integer, String, ForeignKey, Text, Boolean,
@@ -315,7 +316,7 @@ class SqlaTable(Model, BaseDatasource):
     def get_query_str(self, **kwargs):
         engine = self.database.get_sqla_engine()
         qry = self.get_sqla_query(**kwargs)
-        sql = str(
+        sql = six.text_type(
             qry.compile(
                 engine,
                 compile_kwargs={"literal_binds": True}

If this is a mysql query try appending ?charset=utf8 to your SQLAlchemy URI