Skip to content

NamespaceSet.pop() removes item from first backend only, leaving stale references in others #496

@zrgt

Description

@zrgt

Summary

Severity: High
File: sdk/basyx/aas/model/base.py:2046-2050

Description

NamespaceSet.pop() only removes the popped item from the first attribute backend. All remaining backends retain a stale reference.

def pop(self) -> _NSO:
    _, value = next(iter(self._backend.values()))[0].popitem()  # pops from backend[0] only
    self._execute_item_del_hook(value)
    value.parent = None
    return value

self._backend maps each attribute name to its own dict. add() (line 1974-1975) inserts into all backend dicts. pop() only removes from the first one. All remaining backends retain a stale reference to the returned object. Subsequent __contains__, attribute lookups, or remove() calls will find the ghost entry and behave incorrectly.

Fix

After the popitem(), iterate all backends and delete the key for the popped value — the same loop pattern used in remove().

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsdkSomething to do with the `sdk` package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions