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
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