Skip to content

Commit

Permalink
update sort parameter type. add SortValidationError as custom exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Deniz Alpaslan committed Jan 30, 2025
1 parent 32cdc62 commit 107df52
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion arango/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ def all(
:return: Document cursor.
:rtype: arango.cursor.Cursor
:raise arango.exceptions.DocumentGetError: If retrieval fails.
:raise arango.exceptions.SortValidationError: If sort parameters are invalid.
"""
assert is_none_or_int(skip), "skip must be a non-negative int"
assert is_none_or_int(limit), "limit must be a non-negative int"
Expand Down Expand Up @@ -755,7 +756,7 @@ def find(
skip: Optional[int] = None,
limit: Optional[int] = None,
allow_dirty_read: bool = False,
sort: Sequence[Json] = [],
sort: Jsons = [],
) -> Result[Cursor]:
"""Return all documents that match the given filters.
Expand All @@ -767,6 +768,8 @@ def find(
:type limit: int | None
:param allow_dirty_read: Allow reads from followers in a cluster.
:type allow_dirty_read: bool
:param sort: Document sort parameters
:type sort: Jsons
:return: Document cursor.
:rtype: arango.cursor.Cursor
:raise arango.exceptions.DocumentGetError: If retrieval fails.
Expand Down
7 changes: 7 additions & 0 deletions arango/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,3 +1074,10 @@ class JWTRefreshError(ArangoClientError):

class JWTExpiredError(ArangoClientError):
"""JWT token has expired."""


###################################
# Parameter Validation Exceptions #
###################################
class SortValidationError(ArangoClientError):
"""Invalid sort parameters."""
6 changes: 3 additions & 3 deletions arango/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from typing import Any, Iterator, Sequence, Union

from arango.exceptions import DocumentParseError
from arango.typings import Json
from arango.typings import Json, Jsons


@contextmanager
Expand Down Expand Up @@ -148,11 +148,11 @@ def validate_sort_parameters(sort: Sequence[Json]) -> bool:
return True


def build_sort_expression(sort: Sequence[Json]) -> str:
def build_sort_expression(sort: Jsons) -> str:
"""Build a sort condition for an AQL query.
:param sort: Document sort parameters.
:type sort: Sequence[Json]
:type sort: Jsons
:return: The complete AQL sort condition.
:rtype: str
"""
Expand Down

0 comments on commit 107df52

Please # to comment.