Skip to content

[BUG] calling attach_ids on an array blocks append of that array afterwards since 1.4.7 #110

@vincentkoppen

Description

@vincentkoppen

Describe the bug

Before v1.4.7 we could do the following

from power_grid_model_ds import Grid
from power_grid_model_ds.arrays import NodeArray

grid = Grid.empty()
nodes = NodeArray.empty(2)
grid.attach_ids(nodes)
grid.append(nodes)

But after the merge of #92 this raises an error:
ValueError: Cannot append: minimum id 1 is not greater than the current id counter 2

Cause
The attach_ids already updates the internal counter, this is sensible on the one hand since this allows you to do something like:

grid = Grid.empty()
nodes = NodeArray.empty(1)
lines = LineArray.empty(1)
grid.attach_ids(nodes)
grid.attach_ids(lines)

where the node will have id 1 and the line will have id 2.
However it blocks the example given above.

Solution
The change in 1.4.7 was a breaking change for our code, since we used the flow as described.
Personally I view the described flow that now breaks as a valid one. We use it so that we know what the id will be of a certain index of the array that we add to the grid. This seems like a useful thing to have.

The solutions I see for now:

  1. If you want the flow described, you need to set check_max_ids to False (our current fix).
  2. We do no longer update the internal counter within attach_ids. This breaks the flow in the Cause section.
  3. The append returns a list of ids that match their index. Removing the need for attach_ids

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions