Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for sort in collection.find function #359

Merged
merged 7 commits into from
Jan 31, 2025

Conversation

denizalpaslan
Copy link
Contributor

@denizalpaslan denizalpaslan commented Jan 26, 2025

add support for sorting by multiple fields in collection.find function

Copy link
Member

@apetenchea apetenchea left a comment

Choose a reason for hiding this comment

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

I like the idea!

Left some remarks, but nothing major.

arango/collection.py Outdated Show resolved Hide resolved
arango/utils.py Outdated
:type sort: Sequence[Json]
:return: Validation success.
:rtype: bool
:raise arango.exceptions.DocumentGetError: If sort parameters are invalid.
Copy link
Member

@apetenchea apetenchea Jan 28, 2025

Choose a reason for hiding this comment

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

The docstring says DocumentGetError, but the function raises DocumentParseError. I think it's better to create a new error type, inheriting ArangoClientError in exceptions.py, use that and fix the docstring (for example, SortValidationError).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I created a new section (Parameter Validation Exceptions) under exceptions.py, which can come handy for other types of validation errors (filter etc.) in the future.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!
Please update the docstring of this function using the newly created SortValidationError, along with the two raise statements at lines 143 and 147.

arango/utils.py Outdated Show resolved Hide resolved
tests/test_document.py Show resolved Hide resolved
@denizalpaslan
Copy link
Contributor Author

So I see one of the tests (tests/test_cursor.py::test_cursor_from_execute_query[db0]) is failing for some python versions. Not sure if this is pertinent to my change but for the first commit they were not failing. Same test is passing on my local env (python 3.12.4). Any idea?

@apetenchea
Copy link
Member

So I see one of the tests (tests/test_cursor.py::test_cursor_from_execute_query[db0]) is failing for some python versions. Not sure if this is pertinent to my change but for the first commit they were not failing. Same test is passing on my local env (python 3.12.4). Any idea?

Don't worry about these failing tests, they are unrelated. I'll fix them in #360

Copy link
Member

@apetenchea apetenchea left a comment

Choose a reason for hiding this comment

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

Only validate_sort_parameters remains to be fixed, with regards to raising exceptions.

arango/collection.py Outdated Show resolved Hide resolved
arango/collection.py Outdated Show resolved Hide resolved
arango/utils.py Outdated
:type sort: Sequence[Json]
:return: Validation success.
:rtype: bool
:raise arango.exceptions.DocumentGetError: If sort parameters are invalid.
Copy link
Member

Choose a reason for hiding this comment

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

Thanks!
Please update the docstring of this function using the newly created SortValidationError, along with the two raise statements at lines 143 and 147.

denizalpaslan and others added 2 commits January 30, 2025 23:26
Co-authored-by: Alex Petenchea <[email protected]>
Co-authored-by: Alex Petenchea <[email protected]>
@apetenchea
Copy link
Member

In order to merge, please make sure linter is passing

arango/collection.py:789: error: Argument 1 to "build_sort_expression" has incompatible type "list[dict[str, Any]] | None"; expected "list[dict[str, Any]]"  [arg-type]
Found 1 error in 1 file (checked 27 source files)

@denizalpaslan
Copy link
Contributor Author

In order to merge, please make sure linter is passing

arango/collection.py:789: error: Argument 1 to "build_sort_expression" has incompatible type "list[dict[str, Any]] | None"; expected "list[dict[str, Any]]"  [arg-type]
Found 1 error in 1 file (checked 27 source files)

Done. Linter seems to be passing now.

arango/collection.py Outdated Show resolved Hide resolved
Copy link
Member

@apetenchea apetenchea left a comment

Choose a reason for hiding this comment

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

LGTM

@apetenchea apetenchea merged commit 8df2fee into arangodb:main Jan 31, 2025
13 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants