Skip to content

Commit

Permalink
fix: Allow exporting saved queries without schema information (#26889)
Browse files Browse the repository at this point in the history
(cherry picked from commit 4c5176e)
  • Loading branch information
sbernauer authored and michael-s-molina committed Feb 1, 2024
1 parent 9133837 commit e82b815
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions superset/queries/saved_queries/commands/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 e82b815

Please sign in to comment.