From 2b95da102e19df1ee14356dbd87f08c9113224df Mon Sep 17 00:00:00 2001 From: John Kearney Date: Mon, 20 Jul 2015 12:36:10 -0700 Subject: [PATCH 1/2] Remove unused exports for env examples --- .env.example | 15 ++++++--------- setup/files/env | 5 +---- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.env.example b/.env.example index 7e953fcc84..e2d959290b 100644 --- a/.env.example +++ b/.env.example @@ -1,9 +1,6 @@ -REDASH_CONNECTION_ADAPTER=pg -REDASH_CONNECTION_STRING="dbname=data" -REDASH_STATIC_ASSETS_PATH=../rd_ui/app/ -REDASH_GOOGLE_APPS_DOMAIN= -REDASH_ADMINS= -REDASH_WORKERS_COUNT=2 -REDASH_COOKIE_SECRET= -REDASH_DATABASE_URL='postgresql://rd' -REDASH_LOG_LEVEL = "INFO" \ No newline at end of file +export REDASH_STATIC_ASSETS_PATH="../rd_ui/app/" +export REDASH_LOG_LEVEL="INFO" +export REDASH_REDIS_URL=redis://localhost:6379/1 +export REDASH_DATABASE_URL="postgresql://redash" +export REDASH_COOKIE_SECRET=veryverysecret +export REDASH_GOOGLE_APPS_DOMAIN= diff --git a/setup/files/env b/setup/files/env index a58ba81b20..7d468f86c3 100644 --- a/setup/files/env +++ b/setup/files/env @@ -1,9 +1,6 @@ -export REDASH_CONNECTION_ADAPTER=pg -export REDASH_CONNECTION_STRING="dbname=redash" export REDASH_STATIC_ASSETS_PATH="../rd_ui/dist/" export REDASH_LOG_LEVEL="INFO" -export REDASH_WORKERS_COUNT=6 export REDASH_REDIS_URL=redis://localhost:6379/1 export REDASH_DATABASE_URL="postgresql://redash" export REDASH_COOKIE_SECRET=veryverysecret -export REDASH_GOOGLE_APPS_DOMAIN= \ No newline at end of file +export REDASH_GOOGLE_APPS_DOMAIN= From c4502b2925ad5611dcd66e161da9c6de087bd078 Mon Sep 17 00:00:00 2001 From: John Kearney Date: Mon, 20 Jul 2015 14:17:51 -0700 Subject: [PATCH 2/2] Add a more use-friendly message when redshift returns no rows --- redash/query_runner/pg.py | 47 +++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/redash/query_runner/pg.py b/redash/query_runner/pg.py index 1393773100..4f4ad9165f 100644 --- a/redash/query_runner/pg.py +++ b/redash/query_runner/pg.py @@ -127,35 +127,38 @@ def run_query(self, query): columns = [] duplicates_counter = 1 - for column in cursor.description: - # TODO: this deduplication needs to be generalized and reused in all query runners. - column_name = column.name - if column_name in column_names: - column_name += str(duplicates_counter) - duplicates_counter += 1 - - column_names.append(column_name) - - columns.append({ - 'name': column_name, - 'friendly_name': column_name, - 'type': types_map.get(column.type_code, None) - }) - - rows = [dict(zip(column_names, row)) for row in cursor] - - data = {'columns': columns, 'rows': rows} - json_data = json.dumps(data, cls=JSONEncoder) - error = None - cursor.close() + if cursor.description is not None: + for column in cursor.description: + # TODO: this deduplication needs to be generalized and reused in all query runners. + column_name = column.name + if column_name in column_names: + column_name += str(duplicates_counter) + duplicates_counter += 1 + + column_names.append(column_name) + + columns.append({ + 'name': column_name, + 'friendly_name': column_name, + 'type': types_map.get(column.type_code, None) + }) + + rows = [dict(zip(column_names, row)) for row in cursor] + + data = {'columns': columns, 'rows': rows} + error = None + json_data = json.dumps(data, cls=JSONEncoder) + else: + error = 'Query completed but it returned no data.' + json_data = None except (select.error, OSError) as e: logging.exception(e) error = "Query interrupted. Please retry." json_data = None except psycopg2.DatabaseError as e: logging.exception(e) - json_data = None error = e.message + json_data = None except KeyboardInterrupt: connection.cancel() error = "Query cancelled by user."