Fix ci_max after new base-client release#210
Fix ci_max after new base-client release#210Marenz wants to merge 2 commits intofrequenz-floss:v0.x.xfrom
Conversation
Marenz
commented
Sep 2, 2025
- Fix call of stream_method in latest base-client
- Add Mock for initial_metadata() for base-clients GrpcStreamer
Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
There was a problem hiding this comment.
Pull Request Overview
This PR fixes compatibility issues with a new base-client release by updating the streaming interface and adding necessary mock functionality.
- Updates the
StreamMicrogridDispatchesmethod to return a mock stream object instead of an async iterator - Removes unnecessary type casting in the client's stream method call
- Adds a
_MockStreamclass to provide theinitial_metadata()method required by the base-client's GrpcStreamer
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/frequenz/client/dispatch/test/_service.py | Adds _MockStream class and refactors StreamMicrogridDispatches to return mock stream object |
| src/frequenz/client/dispatch/_client.py | Removes type casting from stream method call to fix compatibility |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| async def initial_metadata(self) -> None: | ||
| """Do nothing, just to mock the grpc call.""" | ||
| _logger.debug("Called initial_metadata()") | ||
|
|
There was a problem hiding this comment.
The initial_metadata() method should return metadata instead of None to properly mock the gRPC interface. Consider returning an empty metadata object or the expected metadata type.
| async def initial_metadata(self) -> None: | |
| """Do nothing, just to mock the grpc call.""" | |
| _logger.debug("Called initial_metadata()") | |
| async def initial_metadata(self) -> list: | |
| """Return empty metadata to mock the grpc call.""" | |
| _logger.debug("Called initial_metadata()") | |
| return [] |
| async def stream() -> AsyncIterator[StreamMicrogridDispatchesResponse]: | ||
| """Stream microgrid dispatches changes.""" | ||
| _logger.debug("Starting stream for microgrid %s", request.microgrid_id) |
There was a problem hiding this comment.
[nitpick] The nested stream() function should be extracted to a separate method or moved outside the method to improve readability and maintainability.
| stream_name="StreamMicrogridDispatches", | ||
| stream_method=lambda: cast( | ||
| AsyncIterator[StreamMicrogridDispatchesResponse], | ||
| self.stub.StreamMicrogridDispatches( | ||
| request, | ||
| timeout=self._stream_timeout_seconds, | ||
| ), | ||
| stream_method=lambda: self.stub.StreamMicrogridDispatches( | ||
| request, | ||
| timeout=self._stream_timeout_seconds, | ||
| ), |
There was a problem hiding this comment.
Ah, interesting. Maybe other projects could be affected about this, if they didn't remove the casts after moving to use the proper async stub. 🤔
Once more life shows that there are no small or improbable breaking changes 😢
Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
llucax
left a comment
There was a problem hiding this comment.
LGTM, but now that v0.11.1 is yanked, I would wait until we figure out why is this version failing before we merge this.