Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions superset/commands/database/importers/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def import_database( # noqa: C901
raise ImportFailedError(
"Database doesn't exist and user doesn't have permission to create databases" # noqa: E501
)
# Check if this URI is allowed
if app.config["PREVENT_UNSAFE_DB_CONNECTIONS"]:
# Check if this URI is allowed (skip for system imports like examples)
if app.config["PREVENT_UNSAFE_DB_CONNECTIONS"] and not ignore_permissions:
try:
check_sqlalchemy_uri(make_url_safe(config["sqlalchemy_uri"]))
except SupersetSecurityException as exc:
Expand Down
5 changes: 5 additions & 0 deletions superset/examples/data_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def get_dataset_config_from_yaml(example_dir: Path) -> Dict[str, Optional[str]]:
"table_name": None,
"schema": None,
"data_file": None,
"uuid": None,
}
dataset_yaml = example_dir / "dataset.yaml"
if dataset_yaml.exists():
Expand All @@ -48,6 +49,7 @@ def get_dataset_config_from_yaml(example_dir: Path) -> Dict[str, Optional[str]]:
config = yaml.safe_load(f)
result["table_name"] = config.get("table_name")
result["data_file"] = config.get("data_file")
result["uuid"] = config.get("uuid")
schema = config.get("schema")
# Treat SQLite's 'main' schema as null (use target database default)
result["schema"] = None if schema == "main" else schema
Expand Down Expand Up @@ -81,6 +83,7 @@ def _get_multi_dataset_config(
with open(datasets_yaml) as f:
yaml_config = yaml.safe_load(f)
result["table_name"] = yaml_config.get("table_name") or dataset_name
result["uuid"] = yaml_config.get("uuid")
raw_schema = yaml_config.get("schema")
result["schema"] = None if raw_schema == "main" else raw_schema

Expand Down Expand Up @@ -142,6 +145,7 @@ def discover_datasets() -> Dict[str, Callable[..., None]]:
table_name=table_name,
schema=config["schema"],
data_file=resolved_file,
uuid=config.get("uuid"),
)

# Discover multiple parquet files in data/ folders (complex examples)
Expand All @@ -160,6 +164,7 @@ def discover_datasets() -> Dict[str, Callable[..., None]]:
table_name=config["table_name"],
schema=config["schema"],
data_file=config["data_file"],
uuid=config.get("uuid"),
)

return loaders
Expand Down
7 changes: 7 additions & 0 deletions superset/examples/generic_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def load_parquet_table( # noqa: C901
sample_rows: Optional[int] = None,
data_file: Optional[Any] = None,
schema: Optional[str] = None,
uuid: Optional[str] = None,
) -> SqlaTable:
"""Load a Parquet file into the example database.

Expand Down Expand Up @@ -175,6 +176,10 @@ def safe_serialize(x: Any, column_name: str) -> Optional[str]:
# Set the database reference
tbl.database = database

# Set UUID from YAML config so the YAML import path can find this dataset
if uuid and not tbl.uuid:
tbl.uuid = uuid

if not only_metadata:
# Ensure database reference is set before fetching metadata
if not tbl.database:
Expand All @@ -194,6 +199,7 @@ def create_generic_loader(
sample_rows: Optional[int] = None,
data_file: Optional[Any] = None,
schema: Optional[str] = None,
uuid: Optional[str] = None,
) -> Callable[[Database, SqlaTable], None]:
"""Create a loader function for a specific Parquet file.

Expand Down Expand Up @@ -230,6 +236,7 @@ def loader(
sample_rows=rows,
data_file=data_file,
schema=schema,
uuid=uuid,
)

if description and tbl:
Expand Down
Loading