Skip to content

Commit cc09397

Browse files
committed
Merge branch 'main' into DE-752
2 parents ac2dd4a + b389b80 commit cc09397

File tree

10 files changed

+60
-31
lines changed

10 files changed

+60
-31
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,13 @@ edges.insert({"_from": "students/02", "_to": "lectures/MAT101"})
113113
edges.insert({"_from": "students/02", "_to": "lectures/STA101"})
114114
edges.insert({"_from": "students/03", "_to": "lectures/CSC101"})
115115

116-
# Traverse the graph in outbound direction, breadth-first.
117-
result = graph.traverse(
118-
start_vertex="students/01",
119-
direction="outbound",
120-
strategy="breadthfirst"
121-
)
116+
# Traverse the graph in outbound direction, breath-first.
117+
query = """
118+
FOR v, e, p IN 1..3 OUTBOUND 'students/01' GRAPH 'school'
119+
OPTIONS { bfs: true, uniqueVertices: 'global' }
120+
RETURN {vertex: v, edge: e, path: p}
121+
"""
122+
cursor = db.aql.execute(query)
122123
```
123124

124125
Please see the [documentation](https://docs.python-arango.com) for more details.

arango/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
JwtSuperuserConnection,
1313
)
1414
from arango.database import StandardDatabase
15-
from arango.exceptions import ServerConnectionError
15+
from arango.exceptions import ArangoClientError, ServerConnectionError
1616
from arango.http import (
1717
DEFAULT_REQUEST_TIMEOUT,
1818
DefaultHTTPClient,
@@ -300,6 +300,6 @@ def db(
300300
except ServerConnectionError as err:
301301
raise err
302302
except Exception as err:
303-
raise ServerConnectionError(f"bad connection: {err}")
303+
raise ArangoClientError(f"bad connection: {err}")
304304

305305
return StandardDatabase(connection)

arango/connection.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,13 @@ def ping(self) -> int:
226226
request = Request(method="get", endpoint="/_api/collection")
227227
resp = self.send_request(request)
228228
if resp.status_code in {401, 403}:
229-
raise ServerConnectionError("bad username/password or token is expired")
229+
raise ServerConnectionError(
230+
resp, request, "bad username/password or token is expired"
231+
)
230232
if not resp.is_success: # pragma: no cover
231-
raise ServerConnectionError(resp.error_message or "bad server response")
233+
raise ServerConnectionError(
234+
resp, request, resp.error_message or "bad server response"
235+
)
232236
return resp.status_code
233237

234238
@abstractmethod

arango/database.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,10 +1442,11 @@ def create_collection(
14421442
:raise arango.exceptions.CollectionCreateError: If create fails.
14431443
"""
14441444
key_options: Json = {"type": key_generator, "allowUserKeys": user_keys}
1445-
if key_increment is not None:
1446-
key_options["increment"] = key_increment
1447-
if key_offset is not None:
1448-
key_options["offset"] = key_offset
1445+
if key_generator == "autoincrement":
1446+
if key_increment is not None:
1447+
key_options["increment"] = key_increment
1448+
if key_offset is not None:
1449+
key_options["offset"] = key_offset
14491450

14501451
data: Json = {
14511452
"name": name,

arango/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ class PregelJobDeleteError(ArangoServerError):
614614
#####################
615615

616616

617-
class ServerConnectionError(ArangoClientError):
617+
class ServerConnectionError(ArangoServerError):
618618
"""Failed to connect to ArangoDB server."""
619619

620620

arango/graph.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
__all__ = ["Graph"]
22

33
from typing import List, Optional, Sequence, Union
4+
from warnings import warn
45

56
from arango.api import ApiGroup
67
from arango.collection import EdgeCollection, VertexCollection
@@ -384,6 +385,11 @@ def traverse(
384385
) -> Result[Json]:
385386
"""Traverse the graph and return the visited vertices and edges.
386387
388+
.. warning::
389+
390+
This method is deprecated and no longer works since ArangoDB 3.12.
391+
The preferred way to traverse graphs is via AQL.
392+
387393
:param start_vertex: Start vertex document ID or body with "_id" field.
388394
:type start_vertex: str | dict
389395
:param direction: Traversal direction. Allowed values are "outbound"
@@ -441,6 +447,9 @@ def traverse(
441447
:rtype: dict
442448
:raise arango.exceptions.GraphTraverseError: If traversal fails.
443449
"""
450+
m = "The HTTP traversal API is deprecated since version 3.4.0. The preferred way to traverse graphs is via AQL." # noqa: E501
451+
warn(m, DeprecationWarning, stacklevel=2)
452+
444453
if strategy is not None:
445454
if strategy.lower() == "dfs":
446455
strategy = "depthfirst"

docs/graph.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,10 @@ See :ref:`Graph` and :ref:`EdgeCollection` for API specification.
318318
Graph Traversals
319319
================
320320

321-
**Graph traversals** are executed via the :func:`arango.graph.Graph.traverse`
322-
method. Each traversal can span across multiple vertex collections, and walk
321+
**Graph traversals** are executed via AQL. The old
322+
:func:`arango.graph.Graph.traverse` has been deprecated and can no longer be
323+
used with ArangoDB 3.12 or later.
324+
Each traversal can span across multiple vertex collections, and walk
323325
over edges and vertices using various algorithms.
324326

325327
**Example:**
@@ -371,13 +373,12 @@ over edges and vertices using various algorithms.
371373
teach.insert({'_from': 'teachers/jon', '_to': 'lectures/STA201'})
372374
teach.insert({'_from': 'teachers/jon', '_to': 'lectures/MAT223'})
373375

374-
# Traverse the graph in outbound direction, breath-first.
375-
school.traverse(
376-
start_vertex='teachers/jon',
377-
direction='outbound',
378-
strategy='bfs',
379-
edge_uniqueness='global',
380-
vertex_uniqueness='global',
381-
)
376+
# AQL to perform a graph traversal
377+
query = """
378+
FOR v, e, p IN 1..3 OUTBOUND 'teachers/jon' GRAPH 'school'
379+
OPTIONS { bfs: true, uniqueVertices: 'global' }
380+
RETURN {vertex: v, edge: e, path: p}
381+
"""
382382

383-
See :func:`arango.graph.Graph.traverse` for API specification.
383+
# Traverse the graph in outbound direction, breath-first.
384+
cursor = db.aql.execute(query)

tests/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from arango.client import ArangoClient
1010
from arango.database import StandardDatabase
11-
from arango.exceptions import ServerConnectionError
11+
from arango.exceptions import ArangoClientError, ServerConnectionError
1212
from arango.http import DefaultHTTPClient, DeflateRequestCompression
1313
from arango.resolver import FallbackHostResolver, RandomHostResolver, SingleHostResolver
1414
from tests.helpers import (
@@ -89,7 +89,7 @@ def test_client_bad_connection(db, username, password, cluster):
8989

9090
# Test connection with invalid host URL
9191
client = ArangoClient(hosts="http://127.0.0.1:8500")
92-
with pytest.raises(ServerConnectionError) as err:
92+
with pytest.raises(ArangoClientError) as err:
9393
client.db(db.name, username, password, verify=True)
9494
assert "bad connection" in str(err.value)
9595

tests/test_collection.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,21 @@ def test_collection_management(db, bad_db, cluster):
190190
}
191191
]
192192

193+
col = db.create_collection(
194+
name=col_name, key_generator="autoincrement", key_increment=9, key_offset=100
195+
)
196+
key_options = col.properties()["key_options"]
197+
assert key_options["key_generator"] == "autoincrement"
198+
assert key_options["key_increment"] == 9
199+
assert key_options["key_offset"] == 100
200+
db.delete_collection(col_name)
201+
193202
col = db.create_collection(
194203
name=col_name,
195204
sync=True,
196205
system=False,
197206
key_generator="traditional",
198207
user_keys=False,
199-
key_increment=9,
200-
key_offset=100,
201208
edge=True,
202209
shard_count=2,
203210
shard_fields=["test_attr:"],

tests/test_graph.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import pytest
2+
from packaging import version
3+
14
from arango.collection import EdgeCollection
25
from arango.exceptions import (
36
DocumentDeleteError,
@@ -1071,7 +1074,10 @@ def test_edge_management_via_graph(graph, ecol, fvcol, fvdocs, tvcol, tvdocs):
10711074
assert len(ecol) == 1
10721075

10731076

1074-
def test_traverse(db):
1077+
def test_traverse(db, db_version):
1078+
if db_version >= version.parse("3.12.0"):
1079+
pytest.skip("Traversal API is no longer available for ArangoDB 3.12+")
1080+
10751081
# Create test graph, vertex and edge collections
10761082
school = db.create_graph(generate_graph_name())
10771083
profs = school.create_vertex_collection(generate_col_name())

0 commit comments

Comments
 (0)