Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

* Widen the version range of api-common to also allow v0.8.x.
* Restrict entsoe client dependency version range up to v0.7.x.
* Listing gridpool orders that do not contain a price or quantity no longer raises an exception. Users must validate orders themselves.

## New Features

Expand Down
14 changes: 0 additions & 14 deletions src/frequenz/client/electricity_trading/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,9 +1316,6 @@ def from_pb(cls, order_detail: electricity_trading_pb2.OrderDetail) -> Self:

Returns:
OrderDetail object corresponding to the protobuf message.

Raises:
ValueError: If the order price and quantity are not specified for a non-canceled order.
"""
od = cls(
order_id=order_detail.order_id,
Expand All @@ -1332,17 +1329,6 @@ def from_pb(cls, order_detail: electricity_trading_pb2.OrderDetail) -> Self:
),
)

# Only cancelled orders are allowed to have missing price or quantity
missing_price_or_quantity = (
od.order.price.amount.is_nan()
or od.order.price.currency == Currency.UNSPECIFIED
or od.order.quantity.mw.is_nan()
)
if missing_price_or_quantity and od.state_detail.state != OrderState.CANCELED:
raise ValueError(
f"Price and quantity must be specified for a non-canceled order (`{od}`)."
)

return od

def to_pb(self) -> electricity_trading_pb2.OrderDetail:
Expand Down
9 changes: 3 additions & 6 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,23 +551,20 @@ def test_order_detail_from_pb() -> None:

def test_order_detail_from_pb_missing_fields() -> None:
"""Test the client order detail type conversion from protobuf with missing fields."""
# Previously missing price or quantity raised an error, now it is handled gracefully.
# Missing price
od_pb1 = electricity_trading_pb2.OrderDetail()
od_pb1.CopyFrom(ORDER_DETAIL_PB)
od_pb1.order.ClearField("price")
# Not allowed for active orders
with pytest.raises(ValueError):
OrderDetail.from_pb(od_pb1)
# But allowed for canceled orders
OrderDetail.from_pb(od_pb1)
od_pb1.state_detail.state = electricity_trading_pb2.OrderState.ORDER_STATE_CANCELED
OrderDetail.from_pb(od_pb1)

# Missing quantity (same logic as above)
od_pb2 = electricity_trading_pb2.OrderDetail()
od_pb2.CopyFrom(ORDER_DETAIL_PB)
od_pb2.order.ClearField("quantity")
with pytest.raises(ValueError):
OrderDetail.from_pb(od_pb2)
OrderDetail.from_pb(od_pb2)
od_pb2.state_detail.state = electricity_trading_pb2.OrderState.ORDER_STATE_CANCELED
OrderDetail.from_pb(od_pb2)

Expand Down