betodealmeida commented on code in PR #34803:
URL: https://github.com/apache/superset/pull/34803#discussion_r2316598587
##########
superset/datasets/api.py:
##########
@@ -1319,9 +1322,12 @@ def render_item_list(item_list: list[dict[str, Any]]) ->
list[dict[str, Any]]:
try:
data[new_key] = func(data[key])
- except TemplateSyntaxError as ex:
- raise SupersetTemplateException(
+ except (TemplateSyntaxError, SupersetSyntaxErrorException) as ex:
+ template_exception = SupersetTemplateException(
f"Unable to render expression from dataset {item_type}.",
- ) from ex
+ )
+
+ template_exception.status = 400
Review Comment:
Yeah, let's change this to a 422, since it's always caused by user input. I
asked Claude to take a look as well, here's what it said:
<hr/>
1. The exception is raised for user-provided template issues:
- Invalid Jinja templates in SQL queries
- Unsafe template values/functions
- Missing or incorrect template parameters
- Recursion errors in user templates
2. There's already a related exception with 400 status:
SupersetTemplateParamsErrorException (line 150-165 in exceptions.py) has status
= 400, showing the pattern for template-related user errors.
3. Current usage shows it's treated as a client error: In
datasets/api.py:1177-1178, when SupersetTemplateException is caught, it returns
a 400 response (self.response_400()), not a 500.
4. All the error scenarios are user mistakes:
- Using unsafe functions in templates
- Infinite recursion in templates
- Invalid partition specifications
- Missing metrics in templates
The fix would be to add status = 400 or status = 422 to
SupersetTemplateException. Given that SupersetTemplateParamsErrorException uses
400 and the API already returns 400 when catching this
exception, 400 would be the most consistent choice.
<hr/>
--
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]