Skip to content

Commit

Permalink
return error on DataTypeDefinition empty
Browse files Browse the repository at this point in the history
  • Loading branch information
schroeder- committed Jul 17, 2022
1 parent 0d006fc commit 3e99668
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion asyncua/common/xmlexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ async def add_etree_datatype(self, obj):
Add a UA data type element to the XML etree
"""
obj_el = await self._add_node_common("UADataType", obj)
dv = await obj.read_attribute(ua.AttributeIds.DataTypeDefinition)
dv = await obj.read_attribute(ua.AttributeIds.DataTypeDefinition,raise_on_bad_status=False)
sdef = dv.Value.Value
if sdef:
# FIXME: can probably get that name somewhere else
Expand Down
20 changes: 18 additions & 2 deletions asyncua/server/address_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
from functools import partial
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional

if TYPE_CHECKING:
from typing import Callable, Dict, List, Union, Tuple
from asyncua.ua.uaprotocol_auto import (
ObjectAttributes, DataTypeAttributes, ReferenceTypeAttributes,
VariableTypeAttributes, VariableAttributes, ObjectTypeAttributes
)
__TYPE_ATTRIBUTES = Union[
__TYPE_ATTRIBUTES = Union[
DataTypeAttributes,
ReferenceTypeAttributes,
VariableTypeAttributes,
Expand Down Expand Up @@ -767,6 +767,10 @@ def read_attribute_value(self, nodeid: ua.NodeId, attr: ua.AttributeIds) -> ua.D
dv = ua.DataValue(StatusCode_=ua.StatusCode(ua.StatusCodes.BadAttributeIdInvalid))
return dv
attval = node.attributes[attr]
if attr == ua.AttributeIds.DataTypeDefinition and not _datatypedefinition_is_valid(attval.value):
# DataTypeDefinition should be a subtype of DataTypeDefinition
dv = ua.DataValue(StatusCode_=ua.StatusCode(ua.StatusCodes.BadAttributeIdInvalid))
return dv
if attval.value_callback:
return attval.value_callback()
return attval.value
Expand Down Expand Up @@ -842,3 +846,15 @@ def delete_datachange_callback(self, handle: int):
def add_method_callback(self, methodid: ua.NodeId, callback: Callable):
node = self._nodes[methodid]
node.call = callback


def _datatypedefinition_is_valid(val: Optional[ua.DataValue]) -> bool:
# Check if DataValue contains SubType of DataTypeDefinition
if val.Value is None:
# Retain statuscode if set
return val.StatusCode is not None
if val.Value.VariantType != ua.VariantType.ExtensionObject:
return False
if issubclass(type(val.Value.Value), ua.DataTypeDefinition):
return True
return False

0 comments on commit 3e99668

Please sign in to comment.