When I append rows to a tabular attribute with append_row(), the new rows are sometimes saved ahead of the existing rows instead of after them. It only happens when rows were deleted from the start or middle of that tabular in an earlier, separate update, for example by hand in MI Viewer.
On our side the request looks correct. Since the tabular isn't destructively edited, AttributeTabular._create_value() in mi_attribute_value_classes.py sends the existing row as an "Update" row and the new rows as "Append" rows, in index order. When the record is exported again, though, the rows come back in a different order.
Here is a minimal example (STK 5.0.0, Granta MI 2024 R2 (24.2.1230.0), Python 3.14), using a tabular attribute with one local point column. The first session.update() only sets up the starting state; the append is a later, separate update:
record = table.search_for_records_by_name("...")[0]
table.bulk_fetch([record], [tabular_definition])
tabular = record.attributes["My Tabular"]
# Earlier edit (could equally be done by hand in MI Viewer):
# start with 3 rows: 8, 9, 1, then delete the first two, leaving 1
tabular.delete_row(1)
tabular.delete_row(0)
record.set_attributes([tabular])
session.update([record])
# Later, separate update: re-export, then append 2 rows: 2, 3
table.bulk_fetch([record], [tabular_definition])
tabular = record.attributes["My Tabular"]
for value in (2.0, 3.0):
tabular.append_row()
tabular.rows[-1].cells_by_column["My Column"].value = value
record.set_attributes([tabular])
session.update([record])
# Re-export again: the rows come back as 2, 1, 3 instead of 1, 2, 3
With a fresh tabular, or one where only trailing rows were deleted, the order is kept (1, 2, 3). My guess is that appended rows get a position based on the row count rather than after the highest existing position, but I can't see the row positions to confirm that.
Is this the intended behavior?
The workaround I'm considering is calling force_destructive_editing() before appending, so every row is sent as new and in order. I haven't tested it yet, and it would give every row a new identity and fail for tabulars with File or Picture cells unless the binary data is exported, so it doesn't feel like the right fix.
Happy to answer any follow up questions about this issue.
Thanks,
Noah