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
Next Next commit
Trino: handle table not found in SQLLab
  • Loading branch information
Khrol committed Dec 25, 2023
commit 12287cdd8f63f36edb81a57c7a12e3b0157ad1a1
9 changes: 6 additions & 3 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,9 +804,12 @@

parsed_schema = parse_js_uri_path_item(schema_name, eval_undefined=True)
table_name = cast(str, parse_js_uri_path_item(table_name))
payload = database.db_engine_spec.extra_table_metadata(
database, table_name, parsed_schema
)
try:
payload = database.db_engine_spec.extra_table_metadata(

Check warning on line 808 in superset/databases/api.py

View check run for this annotation

Codecov / codecov/patch

superset/databases/api.py#L807-L808

Added lines #L807 - L808 were not covered by tests
database, table_name, parsed_schema
)
except NoSuchTableError:
return self.response_404()

Check warning on line 812 in superset/databases/api.py

View check run for this annotation

Codecov / codecov/patch

superset/databases/api.py#L811-L812

Added lines #L811 - L812 were not covered by tests
return self.response(200, **payload)

@expose("/<int:pk>/select_star/<path:table_name>/", methods=("GET",))
Expand Down
15 changes: 15 additions & 0 deletions tests/integration_tests/databases/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,21 @@ def test_get_invalid_table_table_extra_metadata(self):
self.assertEqual(rv.status_code, 200)
self.assertEqual(data, {})

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
"""
from superset.utils.database import get_or_create_db

trino_db = get_or_create_db("trino_examples", "trino://42/sd")
uri = f"api/v1/database/{trino_db.id}/table_extra/wrong_table/null/"
self.login(username="admin")
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"})

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