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 bd60b05678b2c108b1b14d1969fa0ec384ec50dd
Author: Igor Khrol <igor.kh...@automattic.com>
AuthorDate: Thu Jan 11 02:37:18 2024 +0200

    fix: Trino - handle table not found in SQLLab (#26355)
    
    Co-authored-by: John Bodley <4567245+john-bod...@users.noreply.github.com>
---
 superset/db_engine_specs/trino.py              | 26 ++++++++++++++++++++++++++
 tests/unit_tests/db_engine_specs/test_trino.py | 16 ++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/superset/db_engine_specs/trino.py 
b/superset/db_engine_specs/trino.py
index 19c11939c4..cab5b087a9 100644
--- a/superset/db_engine_specs/trino.py
+++ b/superset/db_engine_specs/trino.py
@@ -23,7 +23,9 @@ from typing import Any, TYPE_CHECKING
 
 import simplejson as json
 from flask import current_app
+from sqlalchemy.engine.reflection import Inspector
 from sqlalchemy.engine.url import URL
+from sqlalchemy.exc import NoSuchTableError
 from sqlalchemy.orm import Session
 
 from superset.constants import QUERY_CANCEL_KEY, QUERY_EARLY_CANCEL_KEY, 
USER_AGENT
@@ -334,3 +336,27 @@ class TrinoEngineSpec(PrestoBaseEngineSpec):
         return {
             requests_exceptions.ConnectionError: SupersetDBAPIConnectionError,
         }
+
+    @classmethod
+    def get_indexes(
+        cls,
+        database: Database,
+        inspector: Inspector,
+        table_name: str,
+        schema: str | None,
+    ) -> list[dict[str, Any]]:
+        """
+        Get the indexes associated with the specified schema/table.
+
+        Trino dialect raises NoSuchTableError in get_indexes if table is empty.
+
+        :param database: The database to inspect
+        :param inspector: The SQLAlchemy inspector
+        :param table_name: The table to inspect
+        :param schema: The schema to inspect
+        :returns: The indexes
+        """
+        try:
+            return super().get_indexes(database, inspector, table_name, schema)
+        except NoSuchTableError:
+            return []
diff --git a/tests/unit_tests/db_engine_specs/test_trino.py 
b/tests/unit_tests/db_engine_specs/test_trino.py
index 1b50a683a0..5d6b5174a9 100644
--- a/tests/unit_tests/db_engine_specs/test_trino.py
+++ b/tests/unit_tests/db_engine_specs/test_trino.py
@@ -395,3 +395,19 @@ def test_execute_with_cursor_in_parallel(mocker: 
MockerFixture):
     mock_query.set_extra_json_key.assert_called_once_with(
         key=QUERY_CANCEL_KEY, value=query_id
     )
+
+
+def test_get_indexes_no_table():
+    from sqlalchemy.exc import NoSuchTableError
+
+    from superset.db_engine_specs.trino import TrinoEngineSpec
+
+    db_mock = Mock()
+    inspector_mock = Mock()
+    inspector_mock.get_indexes = Mock(
+        side_effect=NoSuchTableError("The specified table does not exist.")
+    )
+    result = TrinoEngineSpec.get_indexes(
+        db_mock, inspector_mock, "test_table", "test_schema"
+    )
+    assert result == []

Reply via email to