mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
fix: catch no table error (#32640)
(cherry picked from commit 695a20d009)
This commit is contained in:
committed by
Joe Li
parent
f0cfd17dc5
commit
958b29acbc
@@ -19,8 +19,10 @@ from textwrap import dedent
|
||||
from unittest import mock, skipUnless
|
||||
|
||||
import pandas as pd
|
||||
import pytest
|
||||
from flask.ctx import AppContext
|
||||
from sqlalchemy import types # noqa: F401
|
||||
from sqlalchemy.exc import NoSuchTableError
|
||||
from sqlalchemy.sql import select
|
||||
|
||||
from superset.db_engine_specs.presto import PrestoEngineSpec
|
||||
@@ -570,6 +572,27 @@ class TestPrestoDbEngineSpec(SupersetTestCase):
|
||||
assert result["partitions"]["cols"] == ["ds", "hour"]
|
||||
assert result["partitions"]["latest"] == {"ds": "01-01-19", "hour": 1}
|
||||
|
||||
def test_get_extra_table_metadata_no_table_found(self):
|
||||
"""
|
||||
Test get_extra_table_metadata when a NoSuchTableError (simulating NoTableFound)
|
||||
is raised by the database.get_df method.
|
||||
"""
|
||||
# Setup a fake database
|
||||
database = mock.MagicMock()
|
||||
database.get_indexes.return_value = [
|
||||
{"column_names": ["ds"]}
|
||||
] # Return indexes so get_df is called
|
||||
database.get_extra.return_value = {}
|
||||
# Simulate that the table is not found
|
||||
database.get_df.side_effect = NoSuchTableError("Table not found")
|
||||
|
||||
from superset.db_engine_specs.exceptions import SupersetDBAPIProgrammingError
|
||||
|
||||
with pytest.raises(SupersetDBAPIProgrammingError):
|
||||
PrestoEngineSpec.get_extra_table_metadata(
|
||||
database, Table("test_table", "test_schema")
|
||||
)
|
||||
|
||||
def test_presto_where_latest_partition(self):
|
||||
db = mock.Mock()
|
||||
db.get_indexes = mock.Mock(return_value=[{"column_names": ["ds", "hour"]}])
|
||||
|
||||
Reference in New Issue
Block a user