Skip to content

Commit fda5a41

Browse files
authored
fix: build_filter_conditions utils method (#277)
* initial commit (new test should fail) * fix: build_filter_conditions
1 parent 68bf6e2 commit fda5a41

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Diff for: arango/utils.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"is_none_or_str",
77
]
88

9+
import json
910
import logging
1011
from contextlib import contextmanager
1112
from typing import Any, Iterator, Sequence, Union
@@ -119,11 +120,5 @@ def build_filter_conditions(filters: Json) -> str:
119120
if not filters:
120121
return ""
121122

122-
def format_condition(key: str, value: Any) -> str:
123-
if isinstance(value, str):
124-
return f'doc.{key} == "{value}"'
125-
126-
return f"doc.{key} == {value}"
127-
128-
conditions = [format_condition(k, v) for k, v in filters.items()]
123+
conditions = [f"doc.{k} == {json.dumps(v)}" for k, v in filters.items()]
129124
return "FILTER " + " AND ".join(conditions)

Diff for: tests/test_document.py

+6
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,12 @@ def test_document_find(col, bad_col, docs):
11751175
assert len(found) == 1
11761176
assert found[0]["_key"] == "1"
11771177

1178+
# Test find with dict value with None
1179+
data = {"dict": {"foo": "bar", "foo_2": None}}
1180+
col.insert(data)
1181+
found = list(col.find(data))
1182+
assert len(found) == 1
1183+
11781184
# Test find with multiple conditions
11791185
found = list(col.find({"val": 2, "text": "foo"}))
11801186
assert len(found) == 1

0 commit comments

Comments
 (0)