Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions arangoasync/aql.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
AQLQueryClearError,
AQLQueryExecuteError,
AQLQueryExplainError,
AQLQueryHistoryError,
AQLQueryKillError,
AQLQueryListError,
AQLQueryRulesGetError,
Expand Down Expand Up @@ -426,6 +427,25 @@ def response_handler(resp: Response) -> QueryTrackingConfiguration:

return await self._executor.execute(request, response_handler)

async def history(self) -> Result[Json]:
"""Return recently executed AQL queries (admin only).
Returns:
dict: AQL query history.
Raises:
AQLQueryHistoryError: If retrieval fails.
"""
request = Request(method=Method.GET, endpoint="/_admin/server/aql-queries")

def response_handler(resp: Response) -> Json:
if not resp.is_success:
raise AQLQueryHistoryError(resp, request)
result: Json = self.deserializer.loads(resp.raw_body)
return cast(Json, result["result"])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Inconsistent KeyError in History API Handling

The history() method uses direct dictionary access result["result"] which will raise a KeyError if the "result" key is missing from the API response. This is inconsistent with the safer pattern used in the functions() method (line 701) which uses .get("result") with a None check. If the API response doesn't contain a "result" key, a KeyError will be raised instead of the more appropriate AQLQueryHistoryError, making error handling less predictable.

Fix in Cursor Fix in Web


return await self._executor.execute(request, response_handler)

async def queries(self, all_queries: bool = False) -> Result[Jsons]:
"""Return a list of currently running queries.
Expand Down
4 changes: 4 additions & 0 deletions arangoasync/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ class AQLQueryExplainError(ArangoServerError):
"""Failed to parse and explain query."""


class AQLQueryHistoryError(ArangoServerError):
"""Failed to retrieve running AQL queries."""


class AQLQueryKillError(ArangoServerError):
"""Failed to kill the query."""

Expand Down
2 changes: 1 addition & 1 deletion arangoasync/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.2"
__version__ = "1.0.3"
5 changes: 5 additions & 0 deletions tests/test_aql.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
AQLQueryClearError,
AQLQueryExecuteError,
AQLQueryExplainError,
AQLQueryHistoryError,
AQLQueryKillError,
AQLQueryListError,
AQLQueryRulesGetError,
Expand Down Expand Up @@ -96,6 +97,8 @@ async def test_list_queries(superuser, db, bad_db):
_ = await superuser.aql.slow_queries(all_queries=True)
await aql.clear_slow_queries()
await superuser.aql.clear_slow_queries(all_queries=True)
history = await superuser.aql.history()
assert isinstance(history, dict)

with pytest.raises(AQLQueryListError):
_ = await bad_db.aql.queries()
Expand All @@ -109,6 +112,8 @@ async def test_list_queries(superuser, db, bad_db):
_ = await aql.slow_queries(all_queries=True)
with pytest.raises(AQLQueryClearError):
await aql.clear_slow_queries(all_queries=True)
with pytest.raises(AQLQueryHistoryError):
_ = await bad_db.aql.history()

long_running_task.cancel()

Expand Down
Loading