Skip to content

Commit 0af468b

Browse files
authored
Support listing gridpool orders without price or quantity (#182)
When listing, gridpool orders that do not contain a price or quantity were previously considered invalid and raised an exception. Since this prevented listing any set of orders where at least one order was considered invalid, this has been changed and users have to validate orders themselves.
2 parents b91234c + bbd22f1 commit 0af468b

File tree

3 files changed

+4
-20
lines changed

3 files changed

+4
-20
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

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

1213
## New Features
1314

src/frequenz/client/electricity_trading/_types.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,9 +1316,6 @@ def from_pb(cls, order_detail: electricity_trading_pb2.OrderDetail) -> Self:
13161316
13171317
Returns:
13181318
OrderDetail object corresponding to the protobuf message.
1319-
1320-
Raises:
1321-
ValueError: If the order price and quantity are not specified for a non-canceled order.
13221319
"""
13231320
od = cls(
13241321
order_id=order_detail.order_id,
@@ -1332,17 +1329,6 @@ def from_pb(cls, order_detail: electricity_trading_pb2.OrderDetail) -> Self:
13321329
),
13331330
)
13341331

1335-
# Only cancelled orders are allowed to have missing price or quantity
1336-
missing_price_or_quantity = (
1337-
od.order.price.amount.is_nan()
1338-
or od.order.price.currency == Currency.UNSPECIFIED
1339-
or od.order.quantity.mw.is_nan()
1340-
)
1341-
if missing_price_or_quantity and od.state_detail.state != OrderState.CANCELED:
1342-
raise ValueError(
1343-
f"Price and quantity must be specified for a non-canceled order (`{od}`)."
1344-
)
1345-
13461332
return od
13471333

13481334
def to_pb(self) -> electricity_trading_pb2.OrderDetail:

tests/test_types.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -551,23 +551,20 @@ def test_order_detail_from_pb() -> None:
551551

552552
def test_order_detail_from_pb_missing_fields() -> None:
553553
"""Test the client order detail type conversion from protobuf with missing fields."""
554+
# Previously missing price or quantity raised an error, now it is handled gracefully.
554555
# Missing price
555556
od_pb1 = electricity_trading_pb2.OrderDetail()
556557
od_pb1.CopyFrom(ORDER_DETAIL_PB)
557558
od_pb1.order.ClearField("price")
558-
# Not allowed for active orders
559-
with pytest.raises(ValueError):
560-
OrderDetail.from_pb(od_pb1)
561-
# But allowed for canceled orders
559+
OrderDetail.from_pb(od_pb1)
562560
od_pb1.state_detail.state = electricity_trading_pb2.OrderState.ORDER_STATE_CANCELED
563561
OrderDetail.from_pb(od_pb1)
564562

565563
# Missing quantity (same logic as above)
566564
od_pb2 = electricity_trading_pb2.OrderDetail()
567565
od_pb2.CopyFrom(ORDER_DETAIL_PB)
568566
od_pb2.order.ClearField("quantity")
569-
with pytest.raises(ValueError):
570-
OrderDetail.from_pb(od_pb2)
567+
OrderDetail.from_pb(od_pb2)
571568
od_pb2.state_detail.state = electricity_trading_pb2.OrderState.ORDER_STATE_CANCELED
572569
OrderDetail.from_pb(od_pb2)
573570

0 commit comments

Comments
 (0)