Skip to content

Commit

Permalink
Fix browsename uniqueness for properties (#619)
Browse files Browse the repository at this point in the history
* Remove old uniqueness check
Add check that properties are unique in one hierarchy

* Replace old duplicates browsename test with duplicated property browsename test.
Remove duplicated browsename test with different ns.
  • Loading branch information
Fabian Beitler authored Jul 7, 2021
1 parent f30430a commit 0a1741c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 44 deletions.
17 changes: 4 additions & 13 deletions asyncua/server/address_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,20 +259,11 @@ def _add_node(self, item, user, check=True):
return result

if item.ParentNodeId in self._aspace:

# check properties
for ref in self._aspace[item.ParentNodeId].references:
# Check if the Parent has a "HasChild" Reference (or subtype of it) with the Node
if (
ref.ReferenceTypeId.Identifier
in [
ua.ObjectIds.HasChild,
ua.ObjectIds.HasComponent,
ua.ObjectIds.HasProperty,
ua.ObjectIds.HasSubtype,
ua.ObjectIds.HasOrderedComponent,
]
and ref.IsForward
):
if item.BrowseName == ref.BrowseName:
if ref.ReferenceTypeId.Identifier == ua.ObjectIds.HasProperty:
if item.BrowseName.Name == ref.BrowseName.Name:
self.logger.warning(
f"AddNodesItem: Requested Browsename {item.BrowseName.Name}"
f" already exists in Parent Node. ParentID:{item.ParentNodeId} --- "
Expand Down
35 changes: 4 additions & 31 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,25 +1130,13 @@ async def test_import_xml_enum_data_type_definition(opc):
await opc.opc.delete_nodes(n)


async def test_duplicated_browsenames_same_ns(opc):
async def test_duplicated_browsenames_same_ns_protperties(opc):
parentfolder = await opc.opc.nodes.objects.add_folder(2, "parent_folder")
childfolder = await parentfolder.add_folder(2, "child_folder")
childproperty = await parentfolder.add_property(2, "Myproperty1", 123)
try:
childfolder2 = await parentfolder.add_folder(2, "child_folder")
childproperty2 = await parentfolder.add_property(2, "Myproperty", 456)
await opc.opc.delete_nodes([parentfolder])
pytest.fail("Childfolder2 should never be created!")
except:
await opc.opc.delete_nodes([parentfolder])
return


async def test_duplicated_browsenames_different_ns(opc):
parentfolder = await opc.opc.nodes.objects.add_folder(2, "parent_folder")
childfolder = await parentfolder.add_folder(2, "child_folder")
try:
childfolder2 = await parentfolder.add_folder(3, "child_folder")
await opc.opc.delete_nodes([parentfolder])
pytest.fail("Childfolder2 should never be created!")
pytest.fail("childproperty2 should never be created!")
except:
await opc.opc.delete_nodes([parentfolder])
return
Expand Down Expand Up @@ -1275,21 +1263,6 @@ async def test_custom_struct_with_enum(opc):
assert val.MyEnum == ua.MyCustEnum2.tutu


async def test_two_times_enum(opc):
idx = 4

await new_enum(opc.opc, idx, "MyCustEnum5", [
"titi",
"toto",
"tutu",
])

with pytest.raises(ua.uaerrors.BadBrowseNameDuplicated):
await new_enum(opc.opc, idx, "MyCustEnum5", [
"titi",
])


async def test_custom_struct_export(opc):
idx = 4

Expand Down

0 comments on commit 0a1741c

Please sign in to comment.