You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2024/07/16 17:51:34 UTC
(superset) 01/01: fix: set default catalog
This is an automated email from the ASF dual-hosted git repository.
beto pushed a commit to branch more-fixes-catalog-security-manager
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 4b21aaff14a7b45254827f89e088e110c3cbb537
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Tue Jul 16 13:51:25 2024 -0400
fix: set default catalog
---
superset/commands/dataset/create.py | 11 +++++++++--
superset/security/manager.py | 25 ++++++++++++++++---------
2 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/superset/commands/dataset/create.py b/superset/commands/dataset/create.py
index a2d81e548b..2f5a9a8143 100644
--- a/superset/commands/dataset/create.py
+++ b/superset/commands/dataset/create.py
@@ -59,14 +59,21 @@ class CreateDatasetCommand(CreateMixin, BaseCommand):
sql = self._properties.get("sql")
owner_ids: Optional[list[int]] = self._properties.get("owners")
- table = Table(self._properties["table_name"], schema, catalog)
+ database = DatasetDAO.get_database_by_id(database_id)
+ if not catalog:
+ catalog = self._properties["catalog"] = database.get_default_catalog()
+
+ table = Table(
+ self._properties["table_name"],
+ schema,
+ catalog,
+ )
# Validate uniqueness
if not DatasetDAO.validate_uniqueness(database_id, table):
exceptions.append(DatasetExistsValidationError(table))
# Validate/Populate database
- database = DatasetDAO.get_database_by_id(database_id)
if not database:
exceptions.append(DatabaseNotFoundValidationError())
self._properties["database"] = database
diff --git a/superset/security/manager.py b/superset/security/manager.py
index 30cf37f117..3444254542 100644
--- a/superset/security/manager.py
+++ b/superset/security/manager.py
@@ -773,6 +773,8 @@ class SupersetSecurityManager( # pylint: disable=too-many-public-methods
# pylint: disable=import-outside-toplevel
from superset.connectors.sqla.models import SqlaTable
+ catalog = catalog or database.get_default_catalog()
+
if hierarchical and (
self.can_access_database(database)
or (catalog and self.can_access_catalog(database, catalog))
@@ -905,10 +907,11 @@ class SupersetSecurityManager( # pylint: disable=too-many-public-methods
if self.can_access_database(database):
return datasource_names
- if catalog:
- catalog_perm = self.get_catalog_perm(database.database_name, catalog)
- if catalog_perm and self.can_access("catalog_access", catalog_perm):
- return datasource_names
+ # If catalog is not set we need to use the default one.
+ catalog = catalog or database.get_default_catalog()
+ catalog_perm = self.get_catalog_perm(database.database_name, catalog)
+ if catalog_perm and self.can_access("catalog_access", catalog_perm):
+ return datasource_names
if schema:
default_catalog = database.get_default_catalog()
@@ -2182,6 +2185,7 @@ class SupersetSecurityManager( # pylint: disable=too-many-public-methods
database = query.database
database = cast("Database", database)
+ default_catalog = database.get_default_catalog()
if self.can_access_database(database):
return
@@ -2195,19 +2199,22 @@ class SupersetSecurityManager( # pylint: disable=too-many-public-methods
# from the SQLAlchemy URI if possible; if not, we use the SQLAlchemy
# inspector to read it.
default_schema = database.get_default_schema_for_query(query)
- # Determining the default catalog is much easier, because DB engine
- # specs need explicit support for catalogs.
- default_catalog = database.get_default_catalog()
tables = {
Table(
table_.table,
table_.schema or default_schema,
- table_.catalog or default_catalog,
+ table_.catalog or query.catalog,
)
for table_ in extract_tables_from_jinja_sql(query.sql, database)
}
elif table:
- tables = {table}
+ tables = {
+ Table(
+ table.table,
+ table.schema,
+ table.catalog or default_catalog,
+ )
+ }
denied = set()