Skip to content

Conversation

Marenz
Copy link
Contributor

@Marenz Marenz commented Sep 2, 2025

  • Fix call of stream_method in latest base-client
  • Add Mock for initial_metadata() for base-clients GrpcStreamer

@Copilot Copilot AI review requested due to automatic review settings September 2, 2025 16:18
@Marenz Marenz requested review from a team as code owners September 2, 2025 16:18
@github-actions github-actions bot added part:test-utils Affects the test utilities part:dispatcher labels Sep 2, 2025
Copilot

This comment was marked as outdated.

@Marenz Marenz added the cmd:skip-release-notes It is not necessary to update release notes for this PR label Sep 2, 2025
@Marenz Marenz requested a review from Copilot September 2, 2025 16:28
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

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 StreamMicrogridDispatches method to return a mock stream object instead of an async iterator
  • Removes unnecessary type casting in the client's stream method call
  • Adds a _MockStream class to provide the initial_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.

Comment on lines 61 to 64
async def initial_metadata(self) -> None:
"""Do nothing, just to mock the grpc call."""
_logger.debug("Called initial_metadata()")

Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
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 []

Copilot uses AI. Check for mistakes.

Comment on lines +154 to +130
async def stream() -> AsyncIterator[StreamMicrogridDispatchesResponse]:
"""Stream microgrid dispatches changes."""
_logger.debug("Starting stream for microgrid %s", request.microgrid_id)
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

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

[nitpick] The nested stream() function should be extracted to a separate method or moved outside the method to improve readability and maintainability.

Copilot uses AI. Check for mistakes.

Comment on lines -273 to 276
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,
),
Copy link
Contributor

Choose a reason for hiding this comment

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

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 😢

Copy link
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

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

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.

@Marenz Marenz added the status:blocked Other issues must be resolved before this can be worked on label Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmd:skip-release-notes It is not necessary to update release notes for this PR part:dispatcher part:test-utils Affects the test utilities status:blocked Other issues must be resolved before this can be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants