Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Trino - handle table not found in SQLLab #26355

Merged
merged 7 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle non-existing table on extra_table_metadata in TrinoEngineSpec
  • Loading branch information
Khrol committed Jan 9, 2024
commit 123d1f8d7ee437db88f99a8f78e4fa90618cfb56
9 changes: 3 additions & 6 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,12 +804,9 @@ def table_extra_metadata(

parsed_schema = parse_js_uri_path_item(schema_name, eval_undefined=True)
table_name = cast(str, parse_js_uri_path_item(table_name))
try:
payload = database.db_engine_spec.extra_table_metadata(
database, table_name, parsed_schema
)
except NoSuchTableError:
return self.response_404()
payload = database.db_engine_spec.extra_table_metadata(
database, table_name, parsed_schema
)
return self.response(200, **payload)

@expose("/<int:pk>/select_star/<path:table_name>/", methods=("GET",))
Expand Down
5 changes: 4 additions & 1 deletion superset/db_engine_specs/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def extra_table_metadata(
table_name: str,
schema_name: str | None,
) -> dict[str, Any]:
metadata = {}
metadata: dict[str, Any] = {}

if not database.has_table_by_name(table_name):
Khrol marked this conversation as resolved.
Show resolved Hide resolved
return metadata

if indexes := database.get_indexes(table_name, schema_name):
col_names, latest_parts = cls.latest_partition(
Expand Down
5 changes: 3 additions & 2 deletions tests/integration_tests/databases/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,7 @@ def test_get_invalid_table_table_extra_metadata(self):
def test_get_invalid_table_table_extra_metadata_trino(self):
Khrol marked this conversation as resolved.
Show resolved Hide resolved
"""
Database API: Test get invalid table from table extra metadata
Trino dialect
"""
from superset.utils.database import get_or_create_db

Expand All @@ -1352,8 +1353,8 @@ def test_get_invalid_table_table_extra_metadata_trino(self):
rv = self.client.get(uri)
data = json.loads(rv.data.decode("utf-8"))

self.assertEqual(rv.status_code, 404)
self.assertEqual(data, {"message": "Not found"})
self.assertEqual(rv.status_code, 200)
self.assertEqual(data, {})

@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_get_select_star(self):
Expand Down
Loading