Skip to content

Commit a0c5409

Browse files
authored
Traversal API no longer available in 3.12 (#335)
* Emitting warning on graph traversals * Changed docs example * Changing readme example * Skipping traversal test on newer versions
1 parent d5d867c commit a0c5409

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

README.md

+7-6
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/graph.py

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

+12-11
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_graph.py

+7-1
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)