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
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

* The dispatch client now supports the official dispatch domain: `grpc://dispatch.eu-1.staging.api.frequenz.com:443`

## Bug Fixes

* `end_time` was not correctly handling the `None` value when converted from protobuf to pythons `Dispatch` class.

## Upgrading

* Renamed `Client` class to `DispatchApiClient` for clarity.
10 changes: 8 additions & 2 deletions src/frequenz/client/dispatch/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ def from_protobuf(cls, pb_object: PBDispatch) -> "Dispatch":
type=pb_object.data.type,
create_time=to_datetime(pb_object.metadata.create_time),
update_time=to_datetime(pb_object.metadata.modification_time),
end_time=to_datetime(pb_object.metadata.end_time),
end_time=(
to_datetime(pb_object.metadata.end_time)
if pb_object.metadata.HasField("end_time")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have this bug in many places in all API clients. We need to be more careful about optional/non-existing fields... For sure I've seen it in the microgrid API, but I think we are lucky there because most stuff we should check if they exist is always filled by the server, so we are not seeing the effect of the bug there.

else None
),
start_time=to_datetime(pb_object.data.start_time),
duration=(
timedelta(seconds=pb_object.data.duration)
Expand Down Expand Up @@ -324,7 +328,9 @@ def to_protobuf(self) -> PBDispatch:
dispatch_id=self.id,
create_time=to_timestamp(self.create_time),
modification_time=to_timestamp(self.update_time),
end_time=to_timestamp(self.end_time),
end_time=(
to_timestamp(self.end_time) if self.end_time is not None else None
),
),
data=DispatchData(
type=self.type,
Expand Down
20 changes: 20 additions & 0 deletions tests/test_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@ def test_dispatch() -> None:
byweekdays=[Weekday.SUNDAY, Weekday.FRIDAY],
),
),
Dispatch(
id=125,
type="test-3",
create_time=datetime(2024, 3, 10, tzinfo=timezone.utc),
update_time=datetime(2024, 3, 11, tzinfo=timezone.utc),
start_time=datetime(2024, 11, 10, tzinfo=timezone.utc),
end_time=None,
duration=timedelta(seconds=20),
target=[ComponentCategory.BATTERY],
active=False,
dry_run=True,
payload={"key": "value1"},
recurrence=RecurrenceRule(
frequency=Frequency.MONTHLY,
interval=3,
end_criteria=EndCriteria(count=20),
byhours=[1, 12, 23],
byweekdays=[Weekday.SUNDAY, Weekday.FRIDAY],
),
),
):
assert Dispatch.from_protobuf(dispatch.to_protobuf()) == dispatch

Expand Down
Loading