Skip to content

Device.RemoveDataItem skips top-level DataItems collection #231

Open

Description

@ottobolyos

Summary

Device.RemoveDataItem(id) does not iterate the top-level DataItems collection when removing an entry — only the nested Component-tree DataItems are considered. A caller who registers a DataItem directly on a Device (as opposed to on one of its Components) cannot remove it through the public API.

Minimal repro

[Test]
public void Device_RemoveDataItem_Removes_TopLevel_DataItem()
{
    var device = new Device
    {
        Id = "d1",
        Uuid = "d1-uuid",
        Name = "d1",
        Type = Device.TypeId,
    };
    device.AddDataItem(new AvailabilityDataItem(device.Id));   // ID: d1_avail

    Assert.That(device.DataItems.Any(di => di.Id == "d1_avail"), Is.True,
        "precondition — the DataItem is on the top-level Device");

    device.RemoveDataItem("d1_avail");

    Assert.That(device.DataItems.Any(di => di.Id == "d1_avail"), Is.False,
        "post-condition — RemoveDataItem must clear the entry from the top-level DataItems collection");
    // Currently fails: the DataItem remains.
}

Impact

AgentConfiguration.DeviceValidationLevel = Remove calls RemoveDataItem from MTConnectAgent.NormalizeDevice when a generic (unknown-Type) DataItem is encountered. If the offending DataItem sits directly on the Device rather than under a Component, the removal is a no-op and the Device is registered with the invalid DataItem still attached.

Note

Detected during PR #218's Ultrareview cycle 1 (finding F-TEST-009). Pre-existing on master — unrelated to PR #218's diff. Filed for follow-up.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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