Skip to content

Reject unknown specific device identification objects - #2976

Merged
janiversen merged 2 commits into
pymodbus-dev:devfrom
MrAlaskan:fix/device-id-specific-unknown-object-error
Jul 23, 2026
Merged

Reject unknown specific device identification objects#2976
janiversen merged 2 commits into
pymodbus-dev:devfrom
MrAlaskan:fix/device-id-specific-unknown-object-error

Conversation

@MrAlaskan

Copy link
Copy Markdown
Contributor

Summary

Return ILLEGAL_DATA_ADDRESS (0x02) when an individual Read Device Identification request references an unknown object.

Problem

Read Device Identification code 0x04 performs individual access to a single object. The Modbus specification requires the server to return exception code 0x02 when the requested object ID does not match a known object.

Previously, ModbusDeviceIdentification.__getitem__() used setdefault() when reading an object. Accessing an unknown ID therefore inserted it into the identity data with an empty value. DeviceInformationFactory then returned that value as a normal object, and ReadDeviceInformationRequest.datastore_update() constructed a successful response containing a zero-length object instead of returning an exception.

This also meant that simply reading an unknown object modified the device identity state.

Changes

Unknown identity lookups are now non-mutating. For individual access, reserved object IDs and objects that are not configured or have no available value return ILLEGAL_DATA_ADDRESS (0x02). Existing stream-access behavior and valid individual object requests remain unchanged.

Tests verify that a valid specific object is returned normally, unknown object 0x54 and unavailable private object 0xFE return exception code 0x02, and reading an unknown object does not insert it into the identity dictionary.

@janiversen janiversen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve conflicts with merged PRs.

@janiversen janiversen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@janiversen
janiversen merged commit 5656853 into pymodbus-dev:dev Jul 23, 2026
16 checks passed
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.

2 participants