bito-code-review[bot] commented on PR #41196:
URL: https://github.com/apache/superset/pull/41196#issuecomment-4740275464
<!-- Bito Reply -->
The flagged issue is correct. The current implementation only catches
`SupersetSecurityException`, allowing other exceptions (such as
`jinja2.exceptions.TemplateError` from `process_jinja_sql`) to propagate and
cause an unhandled server error. To resolve this, you should catch these
parsing exceptions and map them to a structured `ExecuteSqlResponse`.
Here is the suggested fix for
`superset/mcp_service/sql_lab/tool/execute_sql.py`:
```python
try:
security_manager.raise_for_access(
database=database,
sql=request.sql,
schema=request.schema_name,
catalog=request.catalog,
template_params=request.template_params,
force_dataset_match=True,
)
except (SupersetSecurityException, Exception) as exc:
# Map security or parsing/template errors to a structured
response
error_msg = str(exc) if not isinstance(exc,
SupersetSecurityException) else exc.error.message
return ExecuteSqlResponse(
success=False,
error=error_msg,
error_type=SupersetErrorType.DATABASE_SECURITY_ACCESS_ERROR.value,
)
```
There are no other comments on this PR to address. Would you like me to
implement this change?
**superset/mcp_service/sql_lab/tool/execute_sql.py**
```
try:
security_manager.raise_for_access(
database=database,
sql=request.sql,
schema=request.schema_name,
catalog=request.catalog,
template_params=request.template_params,
force_dataset_match=True,
)
except (SupersetSecurityException, Exception) as exc:
# Map security or parsing/template errors to a structured
response
error_msg = str(exc) if not isinstance(exc,
SupersetSecurityException) else exc.error.message
return ExecuteSqlResponse(
success=False,
error=error_msg,
error_type=SupersetErrorType.DATABASE_SECURITY_ACCESS_ERROR.value,
)
```
--
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]