Skip to content

Commit be3714e

Browse files
zhaorui2022Rui Zhao
andauthored
fix(Presto): catch DatabaseError when testing Presto views (apache#25559)
Co-authored-by: Rui Zhao <[email protected]>
1 parent d0f2c55 commit be3714e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

superset/db_engine_specs/presto.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,11 +1268,11 @@ def get_create_view(
12681268
sql = f"SHOW CREATE VIEW {schema}.{table}"
12691269
try:
12701270
cls.execute(cursor, sql)
1271+
rows = cls.fetch_data(cursor, 1)
1272+
1273+
return rows[0][0]
12711274
except DatabaseError: # not a VIEW
12721275
return None
1273-
rows = cls.fetch_data(cursor, 1)
1274-
1275-
return rows[0][0]
12761276

12771277
@classmethod
12781278
def get_tracking_url(cls, cursor: Cursor) -> str | None:

tests/integration_tests/db_engine_specs/presto_tests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,9 +925,11 @@ def test_get_create_view_exception(self):
925925
def test_get_create_view_database_error(self):
926926
from pyhive.exc import DatabaseError
927927

928-
mock_execute = mock.MagicMock(side_effect=DatabaseError())
928+
mock_execute = mock.MagicMock()
929+
mock_fetch_data = mock.MagicMock(side_effect=DatabaseError())
929930
database = mock.MagicMock()
930931
database.get_raw_connection().__enter__().cursor().execute = mock_execute
932+
database.get_raw_connection().__enter__().cursor().fetchall = mock_fetch_data
931933
schema = "schema"
932934
table = "table"
933935
result = PrestoEngineSpec.get_create_view(database, schema=schema, table=table)

0 commit comments

Comments
 (0)