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)