Skip to content

Commit

Permalink
[Bug fix] Query Results fails to use query which has double quotes in…
Browse files Browse the repository at this point in the history
… column names (#3618)
  • Loading branch information
kravets-levko authored Mar 21, 2019
1 parent c47dd05 commit 4e69b73
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion redash/query_runner/query_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def create_tables_from_query_ids(user, connection, query_ids, cached_query_ids=[


def fix_column_name(name):
return u'"{}"'.format(name.replace(':', '_').replace('.', '_').replace(' ', '_'))
return u'"{}"'.format(re.sub('[:."\s]', '_', name, flags=re.UNICODE))


def create_table(connection, table_name, query_results):
Expand Down
8 changes: 8 additions & 0 deletions tests/query_runner/test_query_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ def test_creates_table_with_colons_in_column_name(self):
create_table(connection, table_name, results)
connection.execute('SELECT 1 FROM query_123')

def test_creates_table_with_double_quotes_in_column_name(self):
connection = sqlite3.connect(':memory:')
results = {'columns': [{'name': 'ga:newUsers'}, {
'name': '"test2"'}], 'rows': [{'ga:newUsers': 123, '"test2"': 2}]}
table_name = 'query_123'
create_table(connection, table_name, results)
connection.execute('SELECT 1 FROM query_123')

def test_creates_table(self):
connection = sqlite3.connect(':memory:')
results = {'columns': [{'name': 'test1'},
Expand Down

0 comments on commit 4e69b73

Please sign in to comment.