betodealmeida commented on code in PR #30721:
URL: https://github.com/apache/superset/pull/30721#discussion_r1822726235
##########
superset/datasets/api.py:
##########
@@ -1179,13 +1185,22 @@ def render_item_list(item_list: list[dict[str, Any]])
-> list[dict[str, Any]]:
for item in item_list
]
- if metrics := data.get("metrics"):
- data["metrics"] = render_item_list(metrics)
+ item_type: str | None = None
+ try:
+ if metrics := data.get("metrics"):
+ item_type = "metric"
+ data["metrics"] = render_item_list(metrics)
- if columns := data.get("columns"):
- data["columns"] = render_item_list(columns)
+ if columns := data.get("columns"):
+ item_type = "column"
+ data["columns"] = render_item_list(columns)
- if sql := data.get("sql"):
- data["rendered_sql"] = processor.process_template(sql)
+ if sql := data.get("sql"):
+ item_type = "query"
+ data["rendered_sql"] = processor.process_template(sql)
+ except TemplateSyntaxError as ex:
+ raise SupersetTemplateException(
+ f"Unable to render expression from dataset {item_type}.",
+ ) from ex
Review Comment:
Could possibly be simplified to:
```python
items = [
("query", "sql", "rendered_sql", processor.process_template),
("metric", "metrics", "metrics", render_item_list),
("column", "columns", "columns", render_item_list),
]
for item_type, key, new_key, func in items:
if key not in data: # or if not data.get(key), potentially
continue
try:
data[new_key] = func(data[key])
except TemplateSyntaxError as ex:
raise SupersetTemplateException(
f"Unable to render expression from dataset {item_type}.",
) from ex
```
But it's perfectly fine as is.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]