Skip to content

Commit

Permalink
[Fix] network id handling (#65)
Browse files Browse the repository at this point in the history
* rename/deprecate net and subnet getter functions

* rename/deprecate net delete functions

* enforce unique net_id when writing network to db, allow duplicate names

* rename _id function arguments to net_id

* bump to 0.3.9
  • Loading branch information
jthurner authored Sep 30, 2024
1 parent 3eb2487 commit b4a2b20
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 134 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [0.3.9]

- BREAKING: inserting multiple networks with the same name does not represent an error anymore, networks are only unique by their net_id (_id field of the collection)
- BREAKING: passing net_id as str will not remap to the project name internally but look up on the _id field
- IMPROVED: fix race condition when calling write_network_to_db without net_id

## [0.3.8]

- BREAKING: specifying variant as list will raise an error instead of a deprecation warning
Expand Down
5 changes: 3 additions & 2 deletions pandahub/api/routers/net.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional, Any

import pandapower as pp
import pandapipes as pps
from fastapi import APIRouter, Depends
from pydantic import BaseModel

Expand All @@ -25,7 +26,7 @@ class GetNetFromDB(BaseModel):

@router.post("/get_net_from_db")
def get_net_from_db(data: GetNetFromDB, ph=Depends(pandahub)):
net = ph.get_net_from_db(**data.model_dump())
net = ph.get_network_by_name(**data.model_dump())
return pp.to_json(net)


Expand All @@ -49,7 +50,7 @@ def write_network_to_db(data: WriteNetwork, ph=Depends(pandahub)):

class BaseCRUDModel(BaseModel):
project_id: str
net: str
net_id: int | str
element_type: str

class GetNetValueModel(BaseCRUDModel):
Expand Down
6 changes: 3 additions & 3 deletions pandahub/api/routers/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class GetVariantsModel(BaseModel):
project_id: str
net_id: int
net_id: int | str

@router.post("/get_variants")
def get_variants(data: GetVariantsModel, ph=Depends(pandahub)):
Expand All @@ -40,7 +40,7 @@ def create_variant(data: CreateVariantModel, ph=Depends(pandahub)):

class DeleteVariantModel(BaseModel):
project_id: str
net_id: int
net_id: int | str
index: int

@router.post("/delete_variant")
Expand All @@ -51,7 +51,7 @@ def delete_variant(data: DeleteVariantModel, ph=Depends(pandahub)):

class UpdateVariantModel(BaseModel):
project_id: str
net_id: int
net_id: int | str
index: int
data: dict

Expand Down
Loading

0 comments on commit b4a2b20

Please sign in to comment.