Skip to content

Commit

Permalink
feat(tags): adjust tag export behavior for charts when called from da…
Browse files Browse the repository at this point in the history
…shboard expo… (#14)

* adjust tag export behavior for charts when called from dashboard export command


---------

Co-authored-by: Asher Manangan <[email protected]>
  • Loading branch information
asher-lab and Asher Manangan authored Nov 15, 2024
1 parent e91ff15 commit 094770e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
29 changes: 17 additions & 12 deletions superset/commands/chart/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# under the License.
# isort:skip_file

import inspect
import logging
from collections.abc import Iterator
from typing import Callable
Expand Down Expand Up @@ -82,7 +81,16 @@ def _file_content(model: Slice) -> str:
file_content = yaml.safe_dump(payload, sort_keys=False)
return file_content

# Change to an instance method
_include_tags: bool = True # Default to True

@classmethod
def disable_tag_export(cls) -> None:
cls._include_tags = False

@classmethod
def enable_tag_export(cls) -> None:
cls._include_tags = True

@staticmethod
def _export(
model: Slice, export_related: bool = True
Expand All @@ -96,13 +104,10 @@ def _export(
yield from ExportDatasetsCommand([model.table.id]).run()

# Check if the calling class is ExportDashboardCommands
if export_related and feature_flag_manager.is_feature_enabled("TAGGING_SYSTEM"):
stack = inspect.stack()
for frame_info in stack:
environ = frame_info.frame.f_locals.get("environ")
if environ:
path_info = environ.get("PATH_INFO")
if path_info:
# Check if PATH_INFO contains the substring 'dashboard/export' else export tags of Charts
if "dashboard/export" not in path_info:
yield from ExportTagsCommand.export(chart_ids=[model.id])
if (
export_related
and ExportChartsCommand._include_tags
and feature_flag_manager.is_feature_enabled("TAGGING_SYSTEM")
):
chart_id = model.id
yield from ExportTagsCommand().export(chart_ids=[chart_id])
2 changes: 2 additions & 0 deletions superset/commands/dashboard/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ def _export(
if export_related:
chart_ids = [chart.id for chart in model.slices]
dashboard_ids = model.id
ExportChartsCommand.disable_tag_export()
yield from ExportChartsCommand(chart_ids).run()
ExportChartsCommand.enable_tag_export()
if feature_flag_manager.is_feature_enabled("TAGGING_SYSTEM"):
yield from ExportTagsCommand.export(
dashboard_ids=dashboard_ids, chart_ids=chart_ids
Expand Down

0 comments on commit 094770e

Please sign in to comment.