You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2023/10/13 12:15:11 UTC
[superset] 02/06: fix(Presto): catch DatabaseError when testing Presto views (#25559)
This is an automated email from the ASF dual-hosted git repository.
michaelsmolina pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 254cc36b17ee5a751ef5cd633b8dc7a045b40616
Author: Rui Zhao <10...@users.noreply.github.com>
AuthorDate: Wed Oct 11 10:31:07 2023 -0700
fix(Presto): catch DatabaseError when testing Presto views (#25559)
Co-authored-by: Rui Zhao <zh...@dropbox.com>
(cherry picked from commit be3714e1314df69627614c5229bacaa7839ccfc6)
---
superset/db_engine_specs/presto.py | 6 +++---
tests/integration_tests/db_engine_specs/presto_tests.py | 4 +++-
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/superset/db_engine_specs/presto.py b/superset/db_engine_specs/presto.py
index fc10099d85..561978f61a 100644
--- a/superset/db_engine_specs/presto.py
+++ b/superset/db_engine_specs/presto.py
@@ -1269,11 +1269,11 @@ class PrestoEngineSpec(PrestoBaseEngineSpec):
sql = f"SHOW CREATE VIEW {schema}.{table}"
try:
cls.execute(cursor, sql)
+ rows = cls.fetch_data(cursor, 1)
+
+ return rows[0][0]
except DatabaseError: # not a VIEW
return None
- rows = cls.fetch_data(cursor, 1)
-
- return rows[0][0]
@classmethod
def get_tracking_url(cls, cursor: Cursor) -> str | None:
diff --git a/tests/integration_tests/db_engine_specs/presto_tests.py b/tests/integration_tests/db_engine_specs/presto_tests.py
index 393f89621c..7e151648a6 100644
--- a/tests/integration_tests/db_engine_specs/presto_tests.py
+++ b/tests/integration_tests/db_engine_specs/presto_tests.py
@@ -925,9 +925,11 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
def test_get_create_view_database_error(self):
from pyhive.exc import DatabaseError
- mock_execute = mock.MagicMock(side_effect=DatabaseError())
+ mock_execute = mock.MagicMock()
+ mock_fetch_data = mock.MagicMock(side_effect=DatabaseError())
database = mock.MagicMock()
database.get_raw_connection().__enter__().cursor().execute = mock_execute
+ database.get_raw_connection().__enter__().cursor().fetchall = mock_fetch_data
schema = "schema"
table = "table"
result = PrestoEngineSpec.get_create_view(database, schema=schema, table=table)