Skip to content

fix: accept subchannel references as stored in the OSW backend - #7

Merged
simontaurus merged 1 commit into
mainfrom
fix/subchannel-references
Aug 5, 2026
Merged

fix: accept subchannel references as stored in the OSW backend#7
simontaurus merged 1 commit into
mainfrom
fix/subchannel-references

Conversation

@simontaurus

Copy link
Copy Markdown
Contributor

Problem

The OSW schema defines subchannels as an array of strings picked from the sibling data_channels by osw_id:

"subchannels": {
  "type": "array",
  "items": {
    "title": "Subchannel reference", "type": "string",
    "watch": {"_channels": "data_channels"},
    "enumSource": [{"source": "_channels", "value": "{{item.osw_id}}"}]
  }
}

Codegen honours that (_model.py: subchannels: list[str] | None), but both controller classes narrowed the field back to a list of OpcUaDataChannel objects. Loading a server from the backend therefore failed:

pydantic.v1.error_wrappers.ValidationError: 2 validation errors for OpcUaDataChannel
subchannels -> 0
  value is not a valid dict (type=type_error.dict)

_handle_datachange_notification calls read_channels(subchannels), which needs .node_id, so objects are still required at runtime.

Change

  • Widen subchannels to Optional[List[Union[str, "OpcUaDataChannel"]]] in both the v1 and v2 controllers, so stored references load and inline objects keep working.
  • Add OpcUaServerMixin.get_channel_by_osw_id(), which searches self and all subdevices and accepts both the full subobject IRI (Item:OSW<tool>#OSW<channel>) and the bare OSW<channel> suffix.
  • Resolve string references in _handle_datachange_notification before reading them.

These are same-page subobject references, not cross-page ones, so range/__iris__ is not the right mechanism here: its lazy resolver loads entities by IRI, and there is no page behind Item:OSWdev#OSWchan.

Tests

6 new tests covering the IRI form, resolution across the subdevice hierarchy, the bare-suffix form, the unknown-id error, and a full serialize/reload/resolve round-trip. 47 pass in test_controller.py; flake8 and black clean.

Verified against live data: loading the vac-station hierarchy from the backend now yields 6 subdevices and 90 channels, with event_name_ebg1.subchannels resolving to ns=4;i=1222 and ns=4;i=1230.

The schema defines subchannels as an array of strings picked from the
sibling data_channels by osw_id, but the controller classes narrowed the
field to a list of OpcUaDataChannel objects. Loading a server from the
backend therefore failed validation with "value is not a valid dict".

Widen the field to accept both forms and add
OpcUaServerMixin.get_channel_by_osw_id(), used by the data change handler
to resolve stored references before reading them.
@simontaurus
simontaurus merged commit 3ed7ccc into main Aug 5, 2026
9 checks passed
@simontaurus
simontaurus deleted the fix/subchannel-references branch August 5, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant