From a0fda13994bb362aacf1f1b425a26a3620d62455 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Thu, 4 Oct 2018 15:00:38 -0400 Subject: [PATCH 1/2] [bigquery] fix swallowed error message When getting a "Cannot query over table (...) without a filter over column(s) (...)", the re-raising happening gobbles up the error message and the context is lost. This may or may not be the right fix, but clearly highlights the issue of `self._query_job.errors` being `None` in that particular context. When that is the case, the only context available is that of `DatabaseError` without any details which clearly isn't enough detail. It seems like wrapping the exception into another exception works as expected and shows both stack traces as shown here: --- bigquery/google/cloud/bigquery/dbapi/cursor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bigquery/google/cloud/bigquery/dbapi/cursor.py b/bigquery/google/cloud/bigquery/dbapi/cursor.py index c550287ecc4b..9a2557b6e429 100644 --- a/bigquery/google/cloud/bigquery/dbapi/cursor.py +++ b/bigquery/google/cloud/bigquery/dbapi/cursor.py @@ -153,8 +153,8 @@ def execute(self, operation, parameters=None, job_id=None): # Wait for the query to finish. try: self._query_job.result() - except google.cloud.exceptions.GoogleCloudError: - raise exceptions.DatabaseError(self._query_job.errors) + except google.cloud.exceptions.GoogleCloudError as e: + raise exceptions.DatabaseError(self._query_job.errors or e) query_results = self._query_job._query_results self._set_rowcount(query_results) From d52c87f6817b5580b8786dc82c68d2d8e8630a32 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Wed, 10 Oct 2018 09:46:08 -0700 Subject: [PATCH 2/2] Pass just the exception to DatabaseError The errors on the job resource are mostly redundant with the exception information. --- bigquery/google/cloud/bigquery/dbapi/cursor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bigquery/google/cloud/bigquery/dbapi/cursor.py b/bigquery/google/cloud/bigquery/dbapi/cursor.py index 9a2557b6e429..b582860c6045 100644 --- a/bigquery/google/cloud/bigquery/dbapi/cursor.py +++ b/bigquery/google/cloud/bigquery/dbapi/cursor.py @@ -153,8 +153,8 @@ def execute(self, operation, parameters=None, job_id=None): # Wait for the query to finish. try: self._query_job.result() - except google.cloud.exceptions.GoogleCloudError as e: - raise exceptions.DatabaseError(self._query_job.errors or e) + except google.cloud.exceptions.GoogleCloudError as exc: + raise exceptions.DatabaseError(exc) query_results = self._query_job._query_results self._set_rowcount(query_results)