dosubot[bot] commented on issue #29991:
URL: https://github.com/apache/superset/issues/29991#issuecomment-2303970830
<!-- Answer -->
To resolve the "list index out of range" error in the Query history page
when executing a specific query in Starrocks on Apache Superset, you should
check the handling of the `statements` list in the `execute_sql_statements`
function. Specifically, ensure that the list of statements is not empty before
attempting to access its elements.
Here is a potential fix:
1. Add a check to ensure that `statements` is not empty before proceeding
with the execution loop.
```python
def execute_sql_statements(
# pylint: disable=too-many-arguments, too-many-locals,
too-many-statements, too-many-branches
query_id: int,
rendered_query: str,
return_results: bool,
store_results: bool,
start_time: Optional[float],
expand_data: bool,
log_params: Optional[dict[str, Any]],
) -> Optional[dict[str, Any]]:
"""Executes the sql query returns the results."""
if store_results and start_time:
# only asynchronous queries
stats_logger.timing("sqllab.query.time_pending", now_as_float() -
start_time)
query = get_query(query_id)
payload: dict[str, Any] = {"query_id": query_id}
database = query.database
db_engine_spec = database.db_engine_spec
db_engine_spec.patch()
if database.allow_run_async and not results_backend:
raise SupersetErrorException(
SupersetError(
message=__("Results backend is not configured."),
error_type=SupersetErrorType.RESULTS_BACKEND_NOT_CONFIGURED_ERROR,
level=ErrorLevel.ERROR,
)
)
# Breaking down into multiple statements
parsed_query = ParsedQuery(
rendered_query,
engine=db_engine_spec.engine,
)
if not db_engine_spec.run_multiple_statements_as_one:
statements = parsed_query.get_statements()
logger.info(
"Query %s: Executing %i statement(s)", str(query_id),
len(statements)
)
else:
statements = [rendered_query]
logger.info("Query %s: Executing query as a single statement",
str(query_id))
# Check if statements list is empty
if not statements:
raise SupersetErrorException(
SupersetError(
message=__("No valid SQL statements found."),
error_type=SupersetErrorType.INVALID_SQL_STATEMENT_ERROR,
level=ErrorLevel.ERROR,
)
)
logger.info("Query %s: Set query to 'running'", str(query_id))
query.status = QueryStatus.RUNNING
query.start_running_time = now_as_float()
db.session.commit()
# Rest of the function...
```
This check ensures that the `statements` list is not empty before attempting
to execute any SQL statements, which should prevent the "list index out of
range" error
<sup>[[1]](https://github.com/apache/superset/blob/master/superset/sql_lab.py)</sup>.
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
--
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]