From be3714e1314df69627614c5229bacaa7839ccfc6 Mon Sep 17 00:00:00 2001 From: Rui Zhao <105950525+zhaorui2022@users.noreply.github.com> Date: Wed, 11 Oct 2023 10:31:07 -0700 Subject: [PATCH] fix(Presto): catch DatabaseError when testing Presto views (#25559) Co-authored-by: Rui Zhao --- 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 dfb82877a678d..8afa82d9b55d9 100644 --- a/superset/db_engine_specs/presto.py +++ b/superset/db_engine_specs/presto.py @@ -1268,11 +1268,11 @@ def get_create_view( 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 393f89621c1f7..7e151648a645c 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 @@ def test_get_create_view_exception(self): 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)