Skip to content

Commit

Permalink
fix: Allow exporting saved queries without schema information (apache…
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernauer authored Feb 1, 2024
1 parent 4c24585 commit 4c5176e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions superset/commands/query/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ class ExportSavedQueriesCommand(ExportModelsCommand):
def _export(
model: SavedQuery, export_related: bool = True
) -> Iterator[tuple[str, str]]:
# build filename based on database, optional schema, and label
# build filename based on database, optional schema, and label.
# we call secure_filename() multiple times and join the directories afterwards,
# as secure_filename() replaces "/" with "_".
database_slug = secure_filename(model.database.database_name)
schema_slug = secure_filename(model.schema)
query_slug = secure_filename(model.label) or str(model.uuid)
file_name = f"queries/{database_slug}/{schema_slug}/{query_slug}.yaml"
if model.schema is None:
file_name = f"queries/{database_slug}/{query_slug}.yaml"
else:
schema_slug = secure_filename(model.schema)
file_name = f"queries/{database_slug}/{schema_slug}/{query_slug}.yaml"

payload = model.export_to_dict(
recursive=False,
Expand Down

0 comments on commit 4c5176e

Please sign in to comment.