e2nIEE / pandahub

A data hub for pandapower and pandapipes networks based on MongoDB.
Other
12 stars 12 forks source link

[Fix] network id handling #65

Closed jthurner closed 1 week ago

jthurner commented 1 week ago

Make net_id the only unique identifier in a project's network collection, ensure consistent handling when specifying networks by their name or net_id, and fix a race condition when automatically assigning an index on network insertion.

Inserting multiple networks with the same name is not considered an error anymore. Only the assigned net_id, which is saved in the network document on the _id field, is considered unique.

Various functions operating on a single network exist which identify the network by it's name. As this can be ambiguous, alternative functions which identify the network by net_id exist. Using the latter is recommended. The former still work but will throw an exception if multiple networks for the given name exist in the database.

The function which stores networks, write_net_to_db, can optionally be passed a custom value for net_id. This does not have to be an integer, but an incrementing integer is assigned as net_id if no value is passed.

All functions affected by this change print out deprecation warnings with recommendations for replacements.

Possible breaking changes

A special handling of net_id in CRUD functions has been removed. Previously, these functions internally interpreted a passed net_id as the name of a network if it was of type string. This prohibits directly using strings as net_ids.

Function arguments specifying the net_id have sometimes been named net, these are now consistently named net_id to avoid confusion.