Skip to content

Commit

Permalink
Merge pull request #958 from openedx/cag/format-sql
Browse files Browse the repository at this point in the history
feat(assets): format sql templates before import
  • Loading branch information
Ian2012 authored Sep 30, 2024
2 parents e56179f + 98f7544 commit 5877990
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
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

0 comments on commit 5877990

Please sign in to comment.