Skip to content

Commit

Permalink
fix(bigquery): Properly display errors for BigQuery DBs (#22349)
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio-RiveroMartnez committed Dec 7, 2022
1 parent 0dbaaad commit 60a617e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion superset/db_engine_specs/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ def _get_fields(cls, cols: List[Dict[str, Any]]) -> List[Any]:
@classmethod
def parse_error_exception(cls, exception: Exception) -> Exception:
try:
return Exception(str(exception).splitlines()[0].rsplit(":")[1].strip())
return Exception(str(exception).splitlines()[0].strip())
except Exception: # pylint: disable=broad-except
# If for some reason we get an exception, for example, no new line
# We will return the original exception
Expand Down
10 changes: 5 additions & 5 deletions tests/unit_tests/db_engine_specs/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,16 @@ def test_parse_error_message() -> None:
Test that we parse a received message and just extract the useful information.
Example errors:
bigquery error: 400 Table \"case_detail_all_suites\" must be qualified with a dataset (e.g. dataset.table).
bigquery error: 400 Syntax error: Table \"case_detail_all_suites\" must be qualified with a dataset (e.g. dataset.table).
(job ID: ddf30b05-44e8-4fbf-aa29-40bfccaed886)
-----Query Job SQL Follows-----
| . | . | . |\n 1:select * from case_detail_all_suites\n 2:LIMIT 1001\n | . | . | . |
"""
from superset.db_engine_specs.bigquery import BigQueryEngineSpec

message = 'bigquery error: 400 Table "case_detail_all_suites" must be qualified with a dataset (e.g. dataset.table).\n\n(job ID: ddf30b05-44e8-4fbf-aa29-40bfccaed886)\n\n -----Query Job SQL Follows----- \n\n | . | . | . |\n 1:select * from case_detail_all_suites\n 2:LIMIT 1001\n | . | . | . |'
expected_result = '400 Table "case_detail_all_suites" must be qualified with a dataset (e.g. dataset.table).'
message = 'bigquery error: 400 Syntax error: Table "case_detail_all_suites" must be qualified with a dataset (e.g. dataset.table).\n\n(job ID: ddf30b05-44e8-4fbf-aa29-40bfccaed886)\n\n -----Query Job SQL Follows----- \n\n | . | . | . |\n 1:select * from case_detail_all_suites\n 2:LIMIT 1001\n | . | . | . |'
expected_result = 'bigquery error: 400 Syntax error: Table "case_detail_all_suites" must be qualified with a dataset (e.g. dataset.table).'
assert (
str(BigQueryEngineSpec.parse_error_exception(Exception(message)))
== expected_result
Expand All @@ -277,9 +277,9 @@ def test_parse_error_raises_exception() -> None:
"""
from superset.db_engine_specs.bigquery import BigQueryEngineSpec

message = 'bigquery error: 400 Table "case_detail_all_suites" must be qualified with a dataset (e.g. dataset.table).'
message = 'bigquery error: 400 Syntax error: Table "case_detail_all_suites" must be qualified with a dataset (e.g. dataset.table).'
message_2 = "6"
expected_result = '400 Table "case_detail_all_suites" must be qualified with a dataset (e.g. dataset.table).'
expected_result = 'bigquery error: 400 Syntax error: Table "case_detail_all_suites" must be qualified with a dataset (e.g. dataset.table).'
assert (
str(BigQueryEngineSpec.parse_error_exception(Exception(message)))
== expected_result
Expand Down

0 comments on commit 60a617e

Please sign in to comment.