FakeService: filter: Fix field-existance check#212
FakeService: filter: Fix field-existance check#212Marenz merged 1 commit intofrequenz-floss:v0.x.xfrom
Conversation
Signed-off-by: Mathias L. Baumann <[email protected]>
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug in the FakeService filter implementation where field existence was not properly checked before accessing optional protobuf fields. The fix replaces the walrus operator with explicit HasField() checks to correctly determine if optional fields are set.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/frequenz/client/dispatch/test/_service.py | Updates filter logic to use HasField() instead of walrus operator for checking protobuf field existence |
| tests/test_service.py | Adds comprehensive test coverage for start_time and end_time filtering functionality |
| RELEASE_NOTES.md | Documents the bug fix in release notes |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if dispatch.duration and ( | ||
| dispatch.start_time + dispatch.duration < _to_dt(end_from) | ||
| ): |
There was a problem hiding this comment.
The condition check order has changed from the original logic. The original code checked dispatch.duration before the time comparison, but the parentheses now group the time comparison separately. Consider moving dispatch.duration check outside the parentheses to maintain the original short-circuit behavior: if dispatch.duration and dispatch.start_time + dispatch.duration < _to_dt(end_from):
| if dispatch.duration and ( | |
| dispatch.start_time + dispatch.duration < _to_dt(end_from) | |
| ): | |
| if dispatch.duration and dispatch.start_time + dispatch.duration < _to_dt(end_from): |
This PR fixes a bug in the
FakeServicefilter implementation where field existence was not properly checked before accessing optional protobuf fields. The fix replaces the walrus operator with explicitHasField()checks to correctly determine if optional fields are set.