You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2023/01/09 13:18:33 UTC

[GitHub] [superset] dpgaspar commented on a diff in pull request #22624: chore: Migrate /superset/stop_query/ to API v1

dpgaspar commented on code in PR #22624:
URL: https://github.com/apache/superset/pull/22624#discussion_r1064630452


##########
tests/integration_tests/queries/api_tests.py:
##########
@@ -392,3 +393,27 @@ def test_get_list_query_no_data_access(self):
         # rollback changes
         db.session.delete(query)
         db.session.commit()
+
+    @mock.patch("superset.sql_lab.cancel_query")
+    @mock.patch("superset.views.core.db.session")
+    def test_stop_query(self, mock_superset_db_session, mock_sql_lab_cancel_query):
+        """
+        Handles stop query when the DB engine spec does not
+        have a cancel query method.
+        """
+        form_data = {"client_id": "foo"}
+        query_mock = mock.Mock()
+        query_mock.client_id = "foo"
+        query_mock.status = QueryStatus.RUNNING
+        self.login(username="admin")
+        mock_superset_db_session.query().filter_by().one().return_value = query_mock
+        mock_sql_lab_cancel_query.return_value = True
+        rv = self.client.post(
+            "/api/v1/query/stop",
+            data=json.dumps(form_data),
+            content_type="application/json",
+        )
+
+        assert rv.status_code == 200
+        data = json.loads(rv.data.decode("utf-8"))
+        assert data["result"] == "OK"

Review Comment:
   add one test for a non existent `client_id`



##########
superset/queries/dao.py:
##########
@@ -56,3 +60,23 @@ def save_metadata(query: Query, payload: Dict[str, Any]) -> None:
         columns = payload.get("columns", {})
         db.session.add(query)
         query.set_extra_json_key("columns", columns)
+
+    @staticmethod
+    def stop_query(client_id: str) -> None:
+        query = db.session.query(Query).filter_by(client_id=client_id).one()

Review Comment:
   an invalid `client_id` will raise, and the API would return HTTP 500, would be nicer to respond HTTP 404



-- 
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