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

feat(assets): format sql templates before import #958

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import yaml
from copy import deepcopy
from pathlib import Path
from sqlfmt.api import format_string
from sqlfmt.mode import Mode

from superset import security_manager
from superset.extensions import db
Expand Down Expand Up @@ -108,6 +110,9 @@ def write_asset_to_file(asset, asset_name, folder, file_name, roles):
asset["sqlalchemy_uri"] = DATABASES.get(asset["database_name"])
if folder in ["charts", "dashboards", "datasets"]:
for locale in DASHBOARD_LOCALES:
if folder == "datasets":
asset["sql"] = format_string(asset["sql"], mode=Mode(dialect_name="clickhouse"))

updated_asset = generate_translated_asset(
asset, asset_name, folder, locale, roles
)
Expand Down Expand Up @@ -147,7 +152,6 @@ def generate_translated_asset(asset, asset_name, folder, language, roles):
copy = deepcopy(asset)
copy["uuid"] = str(get_localized_uuid(copy["uuid"], language))
copy[asset_name] = get_translation(copy[asset_name], language)

if folder == "dashboards":
copy["slug"] = f"{copy['slug']}-{language}"
copy["description"] = get_translation(copy["description"], language)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ openedx-atlas
ruamel-yaml==0.18.6
sentry-sdk[flask]
urllib3>=1.26.15,<2
shandy-sqlfmt[jinjafmt]==0.21.2