Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Fix the comparison checks
Browse files Browse the repository at this point in the history
The array comparison happens in the same way as normal comparison. Now
that we have support for the different types, the comparison should be
done correctly.
  • Loading branch information
soderluk committed May 9, 2022
1 parent ea5883d commit 473d2ab
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 22 deletions.
10 changes: 0 additions & 10 deletions arangodantic/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,3 @@ class Operators(str, Enum):
Operators.ALL: "all",
Operators.NONE: "none",
}

# List of array comparison operators.
array_comparison_operators = {
Operators.ALL_IN,
Operators.NONE_IN,
Operators.ANY_IN,
Operators.ANY,
Operators.ALL,
Operators.NONE,
}
2 changes: 1 addition & 1 deletion arangodantic/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ async def test_find_with_comparisons(identity_collection):
assert i.name in {"b", "c"}

cursor = await (
Identity.find({"data.aliases": {Operators.ALL_IN: ["foo"]}}, count=True)
Identity.find({"data.aliases": {Operators.ALL_IN: ["foo", "bar"]}}, count=True)
)
async with cursor:
assert len(cursor) == 1
Expand Down
15 changes: 4 additions & 11 deletions arangodantic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Any, Dict, Iterable, List, Optional, Tuple

from arangodantic.directions import DIRECTIONS
from arangodantic.operators import array_comparison_operators, comparison_operators
from arangodantic.operators import comparison_operators

FilterTypes = Optional[Dict[str, Any]]
SortTypes = Optional[Iterable[Tuple[str, str]]]
Expand Down Expand Up @@ -66,16 +66,9 @@ def build_filters(
bind_vars[value_bind_var] = value

# The actual comparison
if operator in array_comparison_operators:
# These operators are checked against the instance.field instead
# of the other way around, e.g. ["foo"] ALL IN i.data.aliases
filter_list.append(
f"@{value_bind_var} {operator} {instance_name}.{field_str}"
)
else:
filter_list.append(
f"{instance_name}.{field_str} {operator} @{value_bind_var}"
)
filter_list.append(
f"{instance_name}.{field_str} {operator} @{value_bind_var}"
)

return filter_list, bind_vars

Expand Down

0 comments on commit 473d2ab

Please sign in to comment.