You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by va...@apache.org on 2025/06/26 05:03:15 UTC

(superset) 01/01: fix: Consider default catalog when getting tables and view lists

This is an automated email from the ASF dual-hosted git repository.

vavila pushed a commit to branch fix/use-default-catalog-get-tables-
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 13ca60ceb8dc5b5b7ab0db6c154391be15cdf1c3
Author: Vitor Avila <vi...@preset.io>
AuthorDate: Thu Jun 26 02:01:21 2025 -0300

    fix: Consider default catalog when getting tables and view lists
---
 superset/models/core.py              |  2 ++
 tests/unit_tests/models/core_test.py | 57 ++++++++++++++++++++++++++++++++++--
 2 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/superset/models/core.py b/superset/models/core.py
index 787c380bea..cd3cfd8b49 100755
--- a/superset/models/core.py
+++ b/superset/models/core.py
@@ -801,6 +801,7 @@ class Database(Model, AuditMixinNullable, ImportExportMixin):  # pylint: disable
         :param force: whether to force refresh the cache
         :return: The table/schema pairs
         """
+        catalog = catalog or self.get_default_catalog()
         try:
             with self.get_inspector(catalog=catalog, schema=schema) as inspector:
                 return {
@@ -835,6 +836,7 @@ class Database(Model, AuditMixinNullable, ImportExportMixin):  # pylint: disable
         :param force: whether to force refresh the cache
         :return: set of views
         """
+        catalog = catalog or self.get_default_catalog()
         try:
             with self.get_inspector(catalog=catalog, schema=schema) as inspector:
                 return {
diff --git a/tests/unit_tests/models/core_test.py b/tests/unit_tests/models/core_test.py
index a7471074cd..e4421ef7f4 100644
--- a/tests/unit_tests/models/core_test.py
+++ b/tests/unit_tests/models/core_test.py
@@ -16,9 +16,8 @@
 # under the License.
 
 # pylint: disable=import-outside-toplevel
-
-
 from datetime import datetime
+from unittest.mock import ANY
 
 import pytest
 from pytest_mock import MockerFixture
@@ -884,6 +883,33 @@ def test_get_all_table_names_in_schema(mocker: MockerFixture) -> None:
     )
 
 
+def test_get_all_table_names_in_schema_default_catalog(mocker: MockerFixture) -> None:
+    """
+    Test the `get_all_table_names_in_schema` method with a DB that supports
+    multiple catalogs.
+    """
+    database = Database(
+        database_name="db",
+        sqlalchemy_uri="postgresql://user:password@host:5432/examples",
+    )
+
+    mocker.patch.object(database, "get_inspector")
+    mocker.patch.object(database, "get_default_catalog", return_value="examples")
+    mock_get_table_names = mocker.patch(
+        "superset.db_engine_specs.postgres.PostgresEngineSpec.get_table_names"
+    )
+
+    database.get_all_table_names_in_schema(
+        catalog=None,
+        schema="public",
+    )
+    mock_get_table_names.assert_called_once_with(
+        database=database,
+        inspector=ANY,
+        schema="public",
+    )
+
+
 def test_get_all_view_names_in_schema(mocker: MockerFixture) -> None:
     """
     Test the `get_all_view_names_in_schema` method.
@@ -912,6 +938,33 @@ def test_get_all_view_names_in_schema(mocker: MockerFixture) -> None:
     )
 
 
+def test_get_all_view_names_in_schema_default_catalog(mocker: MockerFixture) -> None:
+    """
+    Test the `get_all_view_names_in_schema` method with a DB that supports
+    multiple catalogs.
+    """
+    database = Database(
+        database_name="db",
+        sqlalchemy_uri="postgresql://user:password@host:5432/examples",
+    )
+
+    mocker.patch.object(database, "get_inspector")
+    mocker.patch.object(database, "get_default_catalog", return_value="examples")
+    mock_get_view_names = mocker.patch(
+        "superset.db_engine_specs.base.BaseEngineSpec.get_view_names"
+    )
+
+    database.get_all_view_names_in_schema(
+        catalog=None,
+        schema="public",
+    )
+    mock_get_view_names.assert_called_once_with(
+        database=database,
+        inspector=ANY,
+        schema="public",
+    )
+
+
 @pytest.mark.parametrize(
     "sql, limit, force, method, expected",
     [