Open FraterCRC opened 1 month ago
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.
Assigning to @yousoph since she's been taking stock of what is/isn't being exported properly.
Looks closely related to https://github.com/apache/superset/pull/22118, see the discussion in comments there - is @EugeneTorap still actively contributing to Superset?
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 skipid else f"{slug}{model_id}" return filename if slug else str(model_id)
How to reproduce the bug
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(modelname) slug = slug.replace('-', '').lstrip() filename = f"{slug}{model_id}" if slug else "{model_id}" return filename
Checklist