Skip to content

Node add_reference enforces reftype as int instead of NodeId (possible spec misinterpretation) #1896

@lauler1

Description

@lauler1

Description

The current implementation of add_reference (around line 823) enforces that the reftype argument is an int rather than a NodeId. This seems to imply that ReferenceType NodeIds must not only be numeric but also belong to namespace 0.

However, according to the OPC UA specification, this restriction does not appear to be mandated.


Relevant Specification

The only mention of a restriction for ReferenceType NodeIds is in Table 22 of Part 4, Section 5.7.2, which states:

If the Node to add is a ReferenceType Node, its NodeId should be a numeric id. See OPC 10000-3 for a description of ReferenceType NodeIds.

This suggests that numeric NodeIds are recommended for ReferenceType Nodes, but it does not require them to be in namespace 0, nor does it forbid using a NodeId type for custom ReferenceTypes.


Why this matters

  • Custom ReferenceTypes may use numeric NodeIds in other namespaces.
  • Enforcing int instead of NodeId limits flexibility and may break compliance with the specification for custom models.

Expected Behavior

add_reference should accept a NodeId for reftype, not just an int.
If numeric NodeIds are preferred for performance reasons, that should be documented, but not enforced in code.
If numeric NodeIds shall be enforced, that the function should raise an exception, but even so not restrict to only namespace 0.


Steps to Reproduce

  1. Import typechecked from typeguard and decorate a testing function with @typechecked.
  2. Try to add a reference using a custom ReferenceType with a NodeId in a non-zero namespace in the testing function.
  3. Observe that the current implementation only accepts int.

Suggested Fix

Update add_reference to accept NodeId for reftype and handle numeric IDs as a special case for convenience.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions