Fix OrderedNamespaceSet.__setitem__: int remove-before-add and slice exhausted iterator#517
Conversation
slice branch stored exhausted islice iterator back into _order instead of the materialized successful_new_items list, resulting in an empty slice assignment that discarded all newly added items. Fixes eclipse-basyx#494
…ng new add-before-remove caused false AASConstraintViolation when new item shares an attribute (e.g. id_short) with the item being replaced. Fix removes old item first, rolls back if the subsequent add fails. Fixes eclipse-basyx#498
|
Doesn't the new (and old) implementation change the item's index? Doesn't I think the method |
Add test_ordered_namespaceset_int_setitem_preserves_index: build [p0, old, p2], replace index 1 with new (same id_short as old), assert result is [p0, new, p2] — no index shift and no AASConstraintViolation. Addresses review feedback on eclipse-basyx#517
|
On index preservation: The index is preserved — On |
Both int and slice __setitem__ fixes now in one branch. Keep both tests: test_ordered_namespaceset_int_setitem_preserves_index and test_ordered_namespaceset_slice_setitem_preserves_order. Closes eclipse-basyx#494
Fixes #498
Fixes #494
Changes
__setitem__int (index replacement)AASConstraintViolationwhen new item shares an attribute (e.g.id_short) with the item being replacedaddfails__setitem__sliceself._order[s] = new_itemswithself._order[s] = successful_new_items—new_itemsis an exhaustedisliceiterator; assigning it back to the list slice wrote an empty sequence, silently discarding all new itemsTests
test_ordered_namespaceset_int_setitem_preserves_index: builds[p0, old, p2], replaces index 1 withnew(sameid_short), asserts result is[p0, new, p2]— no index shift, noAASConstraintViolationtest_ordered_namespaceset_slice_setitem_preserves_order: replaces a 2-item slice, verifies new items appear at correct positions