Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The awareness check misses valid naive cases, and the new constraint leaves public documentation and examples inaccurate.
Review effort: Balanced
Findings: 3
Open (3)
What changed in this PR
Adds timezone validation and inverted-window warnings to reporting requests.
Changes:
- Rejects timezone-naive client inputs.
- Validates CLI timestamps and warns about inverted ranges.
- Adds client validation tests.
| File | Description |
|---|---|
src/frequenz/client/reporting/_client.py |
Validates request timestamps. |
src/frequenz/client/reporting/cli/__main__.py |
Validates CLI timestamps and warns on inverted ranges. |
tests/test_client_reporting.py |
Tests client-side validation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+66
to
+67
| def _reject_naive(**times: datetime | None) -> None: | ||
| """Raise if any given datetime is timezone-naive. |
| include_bounds: bool = False, | ||
| ) -> Receiver[ComponentsDataBatch]: | ||
| """Return a Receiver for the microgrid component data stream.""" | ||
| _reject_naive(start_time=start_time, end_time=end_time) |
| parsed = datetime.fromisoformat(value) | ||
| if parsed.tzinfo is None: | ||
| raise argparse.ArgumentTypeError( | ||
| f"datetime must include a timezone offset, e.g. {value}+00:00" |
A naive datetime is ambiguous: the wire encoding assumes UTC while datetime.timestamp() assumes local time, so the same value would denote different instants. Reject it at the public request boundary rather than silently pick one meaning. Signed-off-by: cwasicki <[email protected]>
A naive datetime is ambiguous: the wire encoding assumes UTC while datetime.timestamp() assumes local time. Reject it at the argparse boundary so the CLI fails with a clear message instead of a ValueError. Signed-off-by: cwasicki <[email protected]>
An inverted window is a legal but empty range, so the request still runs; at the CLI it is almost always a typo, and the silent empty output gives no hint why. Signed-off-by: cwasicki <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Guards the reporting request time range against two easy mistakes: ambiguous naive datetimes and an inverted window.
start_time/end_timein the client. A naive value is ambiguous, the wire encoding reads it as UTC whiledatetime.timestamp()reads it as local time, so the same input would denote different instants. Theclient now raises rather than silently pick one meaning.
--start/--endarguments, so a naive value fails at argument parsing with a clear message instead of surfacing as aValueErrorlater.--endprecedes--start. The inverted window is still a legal, empty range and the request runs, but at the CLI it is almost always a typo, and the warning explains the otherwise silent empty output.