Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return error on DataTypeDefinition empty #937

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, Generator
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 @@ -768,6 +768,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 @@ -838,3 +842,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