Replies: 11 comments
-
I don't understand this issue, Could you detail it? |
Beta Was this translation helpful? Give feedback.
-
Similar to copy action in role. As shown below This way I can quickly create a new chart based on an existing chart。 |
Beta Was this translation helpful? Give feedback.
-
Hey @LuPan2015 you're correct that Duplicating / Copying charts doesn't exist at the moment as a feature. Two workarounds:
I'm converting this thread to a Github Discussion, since we use Github Issues to focus on bugs in existing functionality :) |
Beta Was this translation helpful? Give feedback.
-
Thanks for these workarounds, I'm using them now but I should say that not having the ability to copy charts has annoyed me for a very long time. So much so that I came to file a feature request (and found this thread that already requested the same) |
Beta Was this translation helpful? Give feedback.
-
I second this. It would be great to have: |
Beta Was this translation helpful? Give feedback.
-
The workarounds certainly work fine, but I'd love a first class option to duplicate a chart. |
Beta Was this translation helpful? Give feedback.
-
I understand that maintaning this project is a lot of work and hence this feature hasn't been of high priority. However, this really feels like a pretty essential feature and shouldn't require workarounds. Are there any plans to introduce it any time soon? I would enjoy the process of creating charts much more (and be a lot quicker) if I could just use charts I had already built before as a starting point 😅 |
Beta Was this translation helpful? Give feedback.
-
As I had to copy quite a lot of charts recently, I figured I might as well hack something together to automate the most annoying steps. This Python script creates a copy of any ZIP archive for an exported chart, swapping the chart's UUID w/ a freshly generated one so that the chart copy can be imported into Superset without errors. import zipfile
import os
import uuid
import shutil
import yaml
import argparse
def unzip_archive(zip_file, extract_to):
"""Unzip the archive to the specified directory."""
with zipfile.ZipFile(zip_file, "r") as zip_ref:
zip_ref.extractall(extract_to)
def edit_yaml_uuid(yaml_file, new_uuid):
"""Edit the YAML file, replacing the uuid property with a new UUID."""
with open(yaml_file, "r") as file:
content = yaml.safe_load(file)
# Assuming the 'uuid' is a top-level property
content["uuid"] = str(new_uuid)
with open(yaml_file, "w") as file:
yaml.dump(content, file)
def zip_directory(directory, output_filename):
"""Zip the directory into a zip file."""
shutil.make_archive(output_filename, "zip", directory)
def copy_chart_zip(zip_file):
new_uuid = uuid.uuid4()
working_dir = f"tmp_{new_uuid}"
# Unzip the archive
unzip_archive(zip_file, working_dir)
chart_parent_dir_path = None
zip_contents = os.listdir(working_dir)
for item in zip_contents:
if item.startswith("chart_export"):
chart_export_dirname = item
chart_parent_dir_path = os.path.join(working_dir, chart_export_dirname)
break
if not chart_parent_dir_path:
shutil.rmtree(working_dir)
raise ValueError(
"Expected ZIP archive to contain a directory starting with 'chart_export'. Are you sure this is a Superset Chart Export ZIP file?"
)
chart_yml_file = None
chart_yml_dir = os.path.join(chart_parent_dir_path, "charts")
if not os.path.exists(chart_yml_dir):
shutil.rmtree(working_dir)
raise ValueError(
"No 'charts' directory found in the extracted folder. Are you sure this is a Superset Chart Export ZIP file?"
)
for root, dirs, files in os.walk(chart_yml_dir):
for file in files:
if file.endswith(".yaml"):
chart_yml_file = os.path.join(root, file)
break
if chart_yml_file:
# Edit the UUID in the .yml file
edit_yaml_uuid(chart_yml_file, new_uuid)
# Create a new zip archive
base_name = os.path.splitext(zip_file)[0] + "_copy"
zip_directory(working_dir, base_name)
# Clean up the extracted files
shutil.rmtree(working_dir)
print(f"New archive created: {base_name}.zip")
else:
shutil.rmtree(working_dir)
raise ValueError(
"No .yaml file found in the 'charts' directory. Are you sure this is a Superset Chart Export ZIP file?"
)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"zip_file", help="The path to the Superset Chart Export ZIP file."
)
args = parser.parse_args()
copy_chart_zip(args.zip_file) Just copy this to a file (e.g. This workaround is required because if you were to just export to ZIP and import it directly back into Superset, it would overwrite the existing chart and NOT create a copy. IIUC, this is essentially equivalent to the first workaround suggested by @srinify, but changing the UUID rather than the name (maybe that was the intention anyway?) |
Beta Was this translation helpful? Give feedback.
-
Copying a chart is very useful when you are taking the dataset and doing some adjustments for a different scenario. Not yet in the road-map? |
Beta Was this translation helpful? Give feedback.
-
I just double checked and I think this can be considered as closed with the "Save as..." feature. |
Beta Was this translation helpful? Give feedback.
-
real helpful feature in practice |
Beta Was this translation helpful? Give feedback.
-
Currently, we can only create a chart from scratch, instead of modifying it based on an existing chart。
Beta Was this translation helpful? Give feedback.
All reactions