From e82b81529639a3cedeba32fcaa98e682033fa9a3 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Thu, 1 Feb 2024 16:12:29 +0100 Subject: [PATCH] fix: Allow exporting saved queries without schema information (#26889) (cherry picked from commit 4c5176eea82e3b168c5d11f130387d5913b33efa) --- superset/queries/saved_queries/commands/export.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/superset/queries/saved_queries/commands/export.py b/superset/queries/saved_queries/commands/export.py index 1b85cda796a91..9fcd90b5f25e1 100644 --- a/superset/queries/saved_queries/commands/export.py +++ b/superset/queries/saved_queries/commands/export.py @@ -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,