Skip to content

Commit 17eecb1

Browse files
authored
fix(trino): handle missing db in migration (#29997)
1 parent 5906890 commit 17eecb1

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

superset/db_engine_specs/presto.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,13 @@ def epoch_to_dttm(cls) -> str:
296296
return "from_unixtime({col})"
297297

298298
@classmethod
299-
def get_default_catalog(cls, database: "Database") -> str | None:
299+
def get_default_catalog(cls, database: Database) -> str | None:
300300
"""
301301
Return the default catalog.
302302
"""
303+
if database.url_object.database is None:
304+
return None
305+
303306
return database.url_object.database.split("/")[0]
304307

305308
@classmethod

tests/unit_tests/db_engine_specs/test_trino.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
# pylint: disable=unused-argument, import-outside-toplevel, protected-access
18+
from __future__ import annotations
19+
1820
import copy
1921
from collections import namedtuple
2022
from datetime import datetime
@@ -719,7 +721,15 @@ def test_adjust_engine_params_catalog_only() -> None:
719721
assert str(uri) == "trino://user:pass@localhost:8080/new_catalog/new_schema"
720722

721723

722-
def test_get_default_catalog() -> None:
724+
@pytest.mark.parametrize(
725+
"sqlalchemy_uri,result",
726+
[
727+
("trino://user:pass@localhost:8080/system", "system"),
728+
("trino://user:pass@localhost:8080/system/default", "system"),
729+
("trino://trino@localhost:8081", None),
730+
],
731+
)
732+
def test_get_default_catalog(sqlalchemy_uri: str, result: str | None) -> None:
723733
"""
724734
Test the ``get_default_catalog`` method.
725735
"""
@@ -728,15 +738,9 @@ def test_get_default_catalog() -> None:
728738

729739
database = Database(
730740
database_name="my_db",
731-
sqlalchemy_uri="trino://user:pass@localhost:8080/system",
732-
)
733-
assert TrinoEngineSpec.get_default_catalog(database) == "system"
734-
735-
database = Database(
736-
database_name="my_db",
737-
sqlalchemy_uri="trino://user:pass@localhost:8080/system/default",
741+
sqlalchemy_uri=sqlalchemy_uri,
738742
)
739-
assert TrinoEngineSpec.get_default_catalog(database) == "system"
743+
assert TrinoEngineSpec.get_default_catalog(database) == result
740744

741745

742746
@patch("superset.db_engine_specs.trino.TrinoEngineSpec.latest_partition")

0 commit comments

Comments
 (0)