Skip to content

Commit

Permalink
Remove usage of deprecated traverse() function (#1066)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchop authored Apr 22, 2024
1 parent 3029e2d commit 0b47eaa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
27 changes: 16 additions & 11 deletions core/database_arango.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,19 +517,24 @@ def get_tags(self) -> List[Tuple["TagRelationship", "Tag"]]:
from core.schemas.graph import TagRelationship
from core.schemas.tag import Tag

traversed = self._db.graph("tags").traverse(
self.extended_id, direction="any", max_depth=1
tag_aql = """
for v, e, p IN 1..1 OUTBOUND @extended_id GRAPH tags
OPTIONS {uniqueVertices: "path"}
RETURN p
"""
tag_paths = list(
self._db.aql.execute(tag_aql, bind_vars={"extended_id": self.extended_id})
)
if not tag_paths:
return []
relationships = []
for path in traversed["paths"]:
if path["edges"]:
tag_data = Tag.load(path["vertices"][1])
edge_data = path["edges"][0]
# edge_data["id"] = edge_data.pop("_id")
edge_data["__id"] = edge_data.pop("_id")
tag_relationship = TagRelationship.load(edge_data)
relationships.append((tag_relationship, tag_data))
self._tags[tag_data.name] = tag_relationship
for path in tag_paths:
tag_data = Tag.load(path["vertices"][1])
edge_data = path["edges"][0]
edge_data["__id"] = edge_data.pop("_id")
tag_relationship = TagRelationship.load(edge_data)
relationships.append((tag_relationship, tag_data))
self._tags[tag_data.name] = tag_relationship
return relationships

# pylint: disable=too-many-arguments
Expand Down
2 changes: 1 addition & 1 deletion extras/docker/dev/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
image: redis:latest

arangodb:
image: arangodb:3.11.8
image: arangodb:latest
ports:
- 127.0.0.1:8529:8529
environment:
Expand Down
3 changes: 2 additions & 1 deletion tests/apiv2/observables.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_get_observable(self):
md5="d41d8cd98f00b204e9800998ecf8427e",
mime_type="inode/x-empty; charset=binary",
).save()
obs.tag(["tag1"])
obs.tag(["tag1", "tag2"])
response = client.get(f"/api/v2/observables/{obs.id}")
self.assertEqual(response.status_code, 200)
data = response.json()
Expand All @@ -48,6 +48,7 @@ def test_get_observable(self):
self.assertEqual(data["md5"], "d41d8cd98f00b204e9800998ecf8427e")
self.assertEqual(data["mime_type"], "inode/x-empty; charset=binary")
self.assertIn("tag1", data["tags"])
self.assertIn("tag2", data["tags"])

def test_post_existing_observable(self):
obs = hostname.Hostname(value="tomchop.me").save()
Expand Down

0 comments on commit 0b47eaa

Please sign in to comment.