You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "DianaLyM (via GitHub)" <gi...@apache.org> on 2024/07/03 18:08:27 UTC
[I] Stop button for queries doesn't work in SQL Lab [superset]
DianaLyM opened a new issue, #29475:
URL: https://github.com/apache/superset/issues/29475
### Bug description
Connected to Apache Kyuubi, stop request returned: {“message”:“Could not cancel query”}
### How to reproduce the bug
When I click stop in SQL Lab, nothing happens.
### Screenshots/recordings
<img width="681" alt="image" src="https://github.com/apache/superset/assets/163909463/9b33bba4-f607-4f47-8044-5869eb94994c">
### Superset version
4.0.1
### Python version
3.9
### Node version
16
### Browser
Chrome
### Additional context
_No response_
### Checklist
- [X] I have searched Superset docs and Slack and didn't find a solution to my problem.
- [X] I have searched the GitHub issue tracker and didn't find a similar bug report.
- [X] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
--
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: notifications-unsubscribe@superset.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Stop button for queries doesn't work in SQL Lab [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on issue #29475:
URL: https://github.com/apache/superset/issues/29475#issuecomment-2767048110
Query cancellation is not supported by all database engines, but if you want to add a db engine spec for Kyuubi to enable this, we'd welcome the PR. Meanwhile closing this since it's been silent for hundreds of days and this is more of a (reasonable!) feature request, while we're trying to keep Issues to bug reports.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Stop button for queries doesn't work in SQL Lab [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas closed issue #29475: Stop button for queries doesn't work in SQL Lab
URL: https://github.com/apache/superset/issues/29475
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Stop button for queries doesn't work in SQL Lab [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
dosubot[bot] commented on issue #29475:
URL: https://github.com/apache/superset/issues/29475#issuecomment-2206965431
<!-- Greeting -->
Hi @DianaLyM! I'm here to help you with bugs, questions, and becoming a contributor. Let's work on this together while we wait for a human maintainer.
<!-- Answer -->
To resolve the issue where the stop button for queries in SQL Lab does not work and results in the error message `{"message":"Could not cancel query"}` when connected to Apache Kyuubi, you need to ensure that the `cancel_query` function is properly implemented for the Kyuubi engine in the `db_engine_spec`.
The `cancel_query` function attempts to cancel a running query by using a cancel query ID stored in the query's extra JSON. If the cancel query ID is not set or the database engine does not support explicit query cancellation, the function will return `False`.
Here is a relevant snippet from the `cancel_query` function:
```python
def cancel_query(query: Query) -> bool:
"""
Cancel a running query.
Note some engines implicitly handle the cancelation of a query and thus no explicit
action is required.
:param query: Query to cancel
:return: True if query cancelled successfully, False otherwise
"""
if query.database.db_engine_spec.has_implicit_cancel():
return True
# Some databases may need to make preparations for query cancellation
query.database.db_engine_spec.prepare_cancel_query(query)
if query.extra.get(QUERY_EARLY_CANCEL_KEY):
# Query has been cancelled prior to being able to set the cancel key.
# This can happen if the query cancellation key can only be acquired after the
# query has been executed
return True
cancel_query_id = query.extra.get(QUERY_CANCEL_KEY)
if cancel_query_id is None:
return False
with query.database.get_sqla_engine(
catalog=query.catalog,
schema=query.schema,
source=QuerySource.SQL_LAB,
) as engine:
with closing(engine.raw_connection()) as conn:
with closing(conn.cursor()) as cursor:
return query.database.db_engine_spec.cancel_query(
cursor, query, cancel_query_id
)
```
Additionally, ensure that the `stop_query` method in the `QueryDAO` class is correctly implemented. The `stop_query` method should handle the query status and call the `cancel_query` function appropriately. Here is the relevant part of the `stop_query` method:
```python
@staticmethod
def stop_query(client_id: str) -> None:
query = db.session.query(Query).filter_by(client_id=client_id).one_or_none()
if not query:
raise QueryNotFoundException(f"Query with client_id {client_id} not found")
if query.status in [
QueryStatus.FAILED,
QueryStatus.SUCCESS,
QueryStatus.TIMED_OUT,
]:
logger.warning(
"Query with client_id could not be stopped: query already complete",
)
return
if not sql_lab.cancel_query(query):
raise SupersetCancelQueryException("Could not cancel query")
query.status = QueryStatus.STOPPED
query.end_time = now_as_float()
```
To fix the issue, ensure that the `db_engine_spec` for Apache Kyuubi correctly implements the `cancel_query` method and handles the `cancel_query_id` appropriately. If the Kyuubi engine does not support explicit query cancellation, you may need to implement a workaround or ensure that the `cancel_query_id` is correctly set and used.
Additionally, in the frontend code, ensure that the `postStopQuery` function in `superset-frontend/src/SqlLab/actions/sqlLab.js` is correctly implemented to handle the stopping of queries. Here is the relevant part of the `postStopQuery` function:
```js
export function postStopQuery(query) {
return function (dispatch) {
return SupersetClient.post({
endpoint: '/api/v1/query/stop',
body: JSON.stringify({ client_id: query.id }),
headers: { 'Content-Type': 'application/json' },
})
.then(() => dispatch(stopQuery(query)))
.then(() => dispatch(addSuccessToast(t('Query was stopped.'))))
.catch(() =>
dispatch(addDangerToast(t('Failed at stopping query. %s', query.id))),
);
};
}
```
Ensure that the `stopQuery` action is dispatched correctly and that the backend endpoint `/api/v1/query/stop` is properly handling the stop request <sup>[[1]](https://github.com/apache/superset/blob/master/superset/sql_lab.py)</sup><sup>[[2]](https://github.com/apache/superset/blob/master/superset/daos/query.py)</sup><sup>[[3]](https://github.com/apache/superset/blob/master/superset-frontend/src/SqlLab/actions/sqlLab.js)</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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org