Skip to content

Commit

Permalink
fix(Presto): catch DatabaseError when testing Presto views (#25559)
Browse files Browse the repository at this point in the history
Co-authored-by: Rui Zhao <zhaorui@dropbox.com>
  • Loading branch information
zhaorui2022 and Rui Zhao authored Oct 11, 2023
1 parent d0f2c55 commit be3714e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions superset/db_engine_specs/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion tests/integration_tests/db_engine_specs/presto_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit be3714e

Please sign in to comment.