Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad export filenames #30308

Open
3 tasks done
FraterCRC opened this issue Sep 17, 2024 · 3 comments
Open
3 tasks done

Bad export filenames #30308

FraterCRC opened this issue Sep 17, 2024 · 3 comments
Assignees

Comments

@FraterCRC
Copy link

Bug description

If you have a model with name in any other than english language you get filename '_{id}' which will not be exported

it is obvious from this code
def get_filename(model_name: str, model_id: int, skip_id: bool = False) -> str:
slug = secure_filename(model_name)
filename = slug if skip_id else f"{slug}_{model_id}"
return filename if slug else str(model_id)

How to reproduce the bug

  1. Go to charts
  2. Сreate chart "Пивко"
  3. Try to import the chart
  4. You get file with name _{id} in charts folder of zip archive
  5. Files with names starting with _ and - are not imported

Screenshots/recordings

No response

Superset version

master / latest-dev

Python version

3.9

Node version

16

Browser

Safari

Additional context

Suggest to do smthing like:

def get_filename(model_name: str, model_id: int, skip_id: bool = False) -> str:
slug = secure_filename(model_name)
slug = slug.replace('-', '').lstrip()
filename = f"{slug}_{model_id}" if slug else "{model_id}"
return filename

Checklist

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
Copy link

dosubot bot commented Sep 17, 2024

Hey @FraterCRC! I'm here to help you with any bugs, questions, or contributions you have for Superset. Let's tackle this together!

To address the issue where non-English model names result in filenames like '_{id}' that are not exported, you can modify the get_filename function to handle non-English characters more gracefully. Here's an improved version of the function:

import unicodedata
import re
from werkzeug.utils import secure_filename

def slugify(value: str) -> str:
    value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
    value = re.sub(r'[^\w\s-]', '', value).strip().lower()
    return re.sub(r'[-\s]+', '-', value)

def get_filename(model_name: str, model_id: int, skip_id: bool = False) -> str:
    slug = slugify(model_name)
    filename = slug if skip_id else f"{slug}_{model_id}"
    return filename if slug else str(model_id)

This slugify function normalizes the string to ASCII, removes non-word characters, and replaces spaces and hyphens with a single hyphen. This should handle non-English characters more gracefully and avoid the issue of filenames like '_{id}'.

In the context of Superset, you can see that the get_filename function is used in the ExportDashboardsCommand class to generate filenames for exported dashboards. By modifying the get_filename function as shown above, you can ensure that non-English model names are handled correctly when exporting dashboards [1][2].

To continue talking to Dosu, mention @dosu.

@rusackas
Copy link
Member

Assigning to @yousoph since she's been taking stock of what is/isn't being exported properly.

@sfirke
Copy link
Member

sfirke commented Sep 17, 2024

Looks closely related to #22118, see the discussion in comments there - is @EugeneTorap still actively contributing to Superset?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants