Skip to content

Commit

Permalink
fix: build_filter_conditions utils method (#277)
Browse files Browse the repository at this point in the history
* initial commit (new test should fail)

* fix: build_filter_conditions
  • Loading branch information
aMahanna authored Aug 31, 2023
1 parent 68bf6e2 commit fda5a41
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 2 additions & 7 deletions arango/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"is_none_or_str",
]

import json
import logging
from contextlib import contextmanager
from typing import Any, Iterator, Sequence, Union
Expand Down Expand Up @@ -119,11 +120,5 @@ def build_filter_conditions(filters: Json) -> str:
if not filters:
return ""

def format_condition(key: str, value: Any) -> str:
if isinstance(value, str):
return f'doc.{key} == "{value}"'

return f"doc.{key} == {value}"

conditions = [format_condition(k, v) for k, v in filters.items()]
conditions = [f"doc.{k} == {json.dumps(v)}" for k, v in filters.items()]
return "FILTER " + " AND ".join(conditions)
6 changes: 6 additions & 0 deletions tests/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,12 @@ def test_document_find(col, bad_col, docs):
assert len(found) == 1
assert found[0]["_key"] == "1"

# Test find with dict value with None
data = {"dict": {"foo": "bar", "foo_2": None}}
col.insert(data)
found = list(col.find(data))
assert len(found) == 1

# Test find with multiple conditions
found = list(col.find({"val": 2, "text": "foo"}))
assert len(found) == 1
Expand Down

0 comments on commit fda5a41

Please sign in to comment.