Skip to content

Conversation

@Marenz
Copy link
Contributor

@Marenz Marenz commented Sep 30, 2025

No description provided.

Copilot AI review requested due to automatic review settings September 30, 2025 16:13
@Marenz Marenz requested review from a team as code owners September 30, 2025 16:13
@Marenz Marenz requested a review from llucax September 30, 2025 16:13
@github-actions github-actions bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:cli Affects the command-line interface part:test-utils Affects the test utilities part:dispatcher labels Sep 30, 2025
Copy link

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 adds support for two new filtering parameters (dispatch_ids and filter_queries) to the dispatch client's list method, enabling more granular filtering of dispatches by specific IDs and text-based queries.

  • Added dispatch_ids parameter for filtering by specific dispatch IDs
  • Added filter_queries parameter for text-based filtering on dispatch ID and type fields with logical OR combining
  • Enhanced CLI with new options for the added filtering capabilities

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/frequenz/client/dispatch/_client.py Added new filtering parameters and documentation to the list method
src/frequenz/client/dispatch/test/_service.py Implemented filtering logic for dispatch_ids and queries in the fake service
src/frequenz/client/dispatch/main.py Added CLI options for the new filtering parameters
tests/test_client.py Added comprehensive test coverage for the filter_queries functionality
RELEASE_NOTES.md Documented the new filtering features

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Marenz Marenz force-pushed the new_filters branch 2 times, most recently from 74b90ad to cb95cc6 Compare October 7, 2025 16:16
@Marenz Marenz requested a review from shsms October 7, 2025 16:19
llucax
llucax previously approved these changes Oct 8, 2025
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.

I didn't look into tests in much details. All minor comments, if you address them, feel free to force-merge after the push.

return True

@staticmethod
def matches_query(_filter: DispatchFilter, dispatch: Dispatch) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def matches_query(_filter: DispatchFilter, dispatch: Dispatch) -> bool:
def matches_query(filter_: DispatchFilter, dispatch: Dispatch) -> bool:

Usually a leading _ is used for unused stuff, if you just want to use a keyword or reserved word in any way, a trailing _ is usually used. If in this case you to shut up pylint, I would add a pylint: disable= instead), otherwise the API looks ugly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I probably can make this a private method, too

Comment on lines 203 to 209
try:
query_id = DispatchId(int(query[1:]))
if dispatch.id == query_id:
matches_any_query = True
break
except ValueError:
# not an int, interpret as exact type match (without the #)
if query[1:] == dispatch.type:
matches_any_query = True
break
Copy link
Contributor

Choose a reason for hiding this comment

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

To make the error detection more fine-grained:

Suggested change
try:
query_id = DispatchId(int(query[1:]))
if dispatch.id == query_id:
matches_any_query = True
break
except ValueError:
# not an int, interpret as exact type match (without the #)
if query[1:] == dispatch.type:
matches_any_query = True
break
try:
int_id = int(query[1:])
except ValueError:
# not an int, interpret as exact type match (without the #)
if query[1:] == dispatch.type:
matches_any_query = True
break
else:
query_id = DispatchId(int_id)
if dispatch.id == query_id:
matches_any_query = True
break

# Name of the parameter in client.list()
filters["target_components"] = target

# Convert dispatch_ids to iterator if present
Copy link
Contributor

Choose a reason for hiding this comment

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

It is pretty obvious you are converting to a iter, the question (what might be of more value in a comment) is why? :)

assert dispatch == service_side_dispatch


# pylint: disable=too-many-locals
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# pylint: disable=too-many-locals
# pylint: disable-next=too-many-locals

@Marenz Marenz merged commit e29b0b3 into frequenz-floss:v0.x.x Oct 9, 2025
5 checks passed
Comment on lines +300 to +302
# Convert dispatch_ids to iterator to match client.list() parameter type
if "dispatch_ids" in filters:
filters["dispatch_ids"] = iter(filters["dispatch_ids"])
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, super minor and irrelevant, but if you can call iter() on it, it is already an iterable, right? Why do you need to call it explicitly? It doesn't hurt to do so, so just out of curiosity...

Oh, wait, I just looked at client.list() and it takes an iterator instead of an iterable, I see. I think we could change it in the future to Iterable, any Iterator is iterable too, so it should work. It is pretty annoying not being able to pass a collection (iterable) directly to list() and having to explicitly convert to an iterator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Marenz Marenz deleted the new_filters branch October 13, 2025 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:cli Affects the command-line interface part:dispatcher part:docs Affects the documentation part:test-utils Affects the test utilities part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants