Skip to content

Commit

Permalink
fix(node): Node.node_id() return invalid address to list elements
Browse files Browse the repository at this point in the history
  • Loading branch information
soofstad committed Nov 7, 2023
1 parent edd6d90 commit 327bbc6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/common/providers/address_resolver/path_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ def get_child(
f"Invalid attribute '{self.path}'. Valid attributes are '{list(entity.keys())}'."
) from ex
else:
try:
int(self.path)
raise NotFoundException(
"'myList.0' is an invalid syntax for accessing items in a list. Use 'myList[0]' instead"
) from ex
except ValueError:
pass
raise NotFoundException(f"Invalid index '{self.path}'. Valid indices are < {len(entity)}.") from ex

return result, self.path
2 changes: 2 additions & 0 deletions src/common/tree/tree_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def node_id(self):
return self.uid
if not self.storage_contained and not self.is_array():
return self.uid
if self.parent.is_array():
return f"{self.parent.node_id}[{self.key}]"
return ".".join((self.parent.node_id, self.key))

def path(self):
Expand Down
4 changes: 4 additions & 0 deletions src/tests/bdd/document/add_document.feature
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ Feature: Add document with document_service
}
"""
Then the response status should be "OK"
And the response should contain
"""
{"uid": "11.phases[1]"}
"""
Given i access the resource url "/api/documents/data-source-name/root_package/EntityPackage/operation1?depth=3"
When I make a "GET" request
Then the response status should be "OK"
Expand Down
2 changes: 1 addition & 1 deletion src/tests/unit/common/tree/test_tree_node_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def test_node_id(self):
self.assertEqual(nested_2.node_id, "1.nested.nested")
self.assertEqual(reference.node_id, "1.nested.nested.reference")
self.assertEqual(list_node.node_id, "1.list")
self.assertEqual(item_1.node_id, "1.list.0")
self.assertEqual(item_1.node_id, "1.list[0]")

def test_search(self):
document_1 = {
Expand Down

0 comments on commit 327bbc6

Please sign in to comment.