Skip to content

Commit 6b457f3

Browse files
committed
Fixed computedValues formatting
1 parent 434f311 commit 6b457f3

File tree

2 files changed

+15
-47
lines changed

2 files changed

+15
-47
lines changed

arango/database.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,9 +1012,9 @@ def create_collection(
10121012
document schema validation.
10131013
:type schema: dict
10141014
:param computedValues: Array of computed values for the new collection
1015-
enabling default values to new documents or the maintenance of
1016-
auxiliary attributes for search queries. Available in ArangoDB
1017-
version 3.10 or greater. See ArangoDB documentation for more
1015+
enabling default values to new documents or the maintenance of
1016+
auxiliary attributes for search queries. Available in ArangoDB
1017+
version 3.10 or greater. See ArangoDB documentation for more
10181018
information on computed values.
10191019
:type computedValues: list
10201020
:return: Standard collection API wrapper.

arango/formatter.py

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any
22

3-
from arango.typings import Headers, Json, Jsons
3+
from arango.typings import Headers, Json
44

55

66
def verify_format(_: Any, res: Json) -> Json:
@@ -210,49 +210,17 @@ def format_collection(body: Json) -> Json:
210210

211211
# New in 3.10
212212
if "computedValues" in body:
213-
result["computedValues"] = format_collection_computed_values(body["computedValues"])
214-
215-
return verify_format(body, result)
216-
217-
218-
def format_collection_computed_values(body: Jsons) -> Jsons:
219-
"""Format collection computed values data.
220-
221-
:param body: Input body.
222-
:type body: dict
223-
:return: Formatted body.
224-
:rtype: dict
225-
"""
226-
result: Jsons = []
227-
228-
for item in body:
229-
result.append(format_collection_computed_value_item(item))
230-
231-
return verify_format(body, result)
232-
233-
234-
def format_collection_computed_value_item(body: Json) -> Json:
235-
"""Format a computed value item for a collection.
236-
237-
:param body: Input body.
238-
:type body: dict
239-
:return: Formatted body.
240-
:rtype: dict
241-
"""
242-
result: Json = {}
243-
244-
if "name" in body:
245-
result["name"] = body["name"]
246-
if "expression" in body:
247-
result["expression"] = body["expression"]
248-
if "overwrite" in body:
249-
result["overwrite"] = body["overwrite"]
250-
if "computedOn" in body:
251-
result["computedOn"] = body["computedOn"]
252-
if "keepNull" in body:
253-
result["keepNull"] = body["keepNull"]
254-
if "failOnWarning" in body:
255-
result["failOnWarning"] = body["failOnWarning"]
213+
result["computedValues"] = [
214+
{
215+
"name": cv["name"],
216+
"expression": cv["expression"],
217+
"overwrite": cv["overwrite"],
218+
"computedOn": cv["computedOn"],
219+
"keepNull": cv["keepNull"],
220+
"failOnWarning": cv["failOnWarning"],
221+
}
222+
for cv in body["computedValues"]
223+
]
256224

257225
return verify_format(body, result)
258226

0 commit comments

Comments
 (0)