Skip to content

Commit 800fafd

Browse files
committed
revert: _ensure_key_in_body changes
(no suitable for client-side functionality)
1 parent 2095fdd commit 800fafd

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

arango/collection.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,13 @@ def _prep_from_doc(
169169
else:
170170
return doc_id, doc_id, {"If-Match": rev}
171171

172-
def _ensure_key_in_body(self, body: Json, index: Optional[int] = None) -> Json:
173-
"""Return the document body with "_key" field populated. If
174-
neither "_key" or "_id" exist, set "_key" value to **index**,
175-
where **index** is the document's position in the sequence.
176-
172+
def _ensure_key_in_body(self, body: Json) -> Json:
173+
"""Return the document body with "_key" field populated.
177174
:param body: Document body.
178175
:type body: dict
179-
:param index: Document index value in the original list of documents.
180-
:param index: int | None
181176
:return: Document body with "_key" field.
182177
:rtype: dict
183-
:raise arango.exceptions.DocumentParseError: On missing _key, _id, & index.
178+
:raise arango.exceptions.DocumentParseError: On missing ID and key.
184179
"""
185180
if "_key" in body:
186181
return body
@@ -189,11 +184,6 @@ def _ensure_key_in_body(self, body: Json, index: Optional[int] = None) -> Json:
189184
body = body.copy()
190185
body["_key"] = doc_id[len(self._id_prefix) :]
191186
return body
192-
elif index is not None:
193-
body = body.copy()
194-
body["_key"] = str(index)
195-
return body
196-
197187
raise DocumentParseError('field "_key" or "_id" required')
198188

199189
def _ensure_key_from_id(self, body: Json) -> Json:
@@ -2001,9 +1991,7 @@ def import_bulk(
20011991
:rtype: dict
20021992
:raise arango.exceptions.DocumentInsertError: If import fails.
20031993
"""
2004-
documents = [
2005-
self._ensure_key_in_body(doc, i) for i, doc in enumerate(documents, 1)
2006-
]
1994+
documents = [self._ensure_key_from_id(doc) for doc in documents]
20071995

20081996
params: Params = {"type": "array", "collection": self.name}
20091997
if halt_on_error is not None:

tests/test_graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_graph_properties(graph, bad_graph, db):
5858

5959

6060
def test_graph_provision(graph, db):
61-
vertices = [{"foo": i} for i in range(1, 101)]
61+
vertices = [{"_key": str(i)} for i in range(1, 101)]
6262
edges = [
6363
{"_from": f"numbers/{j}", "_to": f"numbers/{i}", "result": j / i}
6464
for i in range(1, 101)

0 commit comments

Comments
 (0)