Skip to content

Add is_valid check to OrderDetail#180

Merged
cwasicki merged 1 commit into
frequenz-floss:v0.x.xfrom
cwasicki:valid
Jan 16, 2026
Merged

Add is_valid check to OrderDetail#180
cwasicki merged 1 commit into
frequenz-floss:v0.x.xfrom
cwasicki:valid

Conversation

@cwasicki

@cwasicki cwasicki commented Aug 15, 2025

Copy link
Copy Markdown
Collaborator

Can be used by the user to check the validity of an order, which is
currently defined as any order with a valid price and quantity, or in
cancelled state.

Copilot AI review requested due to automatic review settings August 15, 2025 07:38
@cwasicki cwasicki requested a review from a team as a code owner August 15, 2025 07:38
@github-actions github-actions Bot added the part:tests Affects the unit, integration and performance (benchmarks) tests label Aug 15, 2025

Copilot AI left a comment

Copy link
Copy Markdown

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 optionally listing invalid orders in the gridpool orders endpoint. Previously, the system would raise an error when encountering orders with missing price or quantity fields for non-canceled orders. Now, these orders are considered "invalid" but can still be returned if requested.

  • Modified OrderDetail.from_pb() to no longer raise exceptions for invalid orders
  • Added is_valid property to OrderDetail to check order validity
  • Added valid_only parameter to list_gridpool_orders() to control filtering behavior

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/frequenz/client/electricity_trading/_types.py Removed exception raising from from_pb() and added is_valid property for validation
src/frequenz/client/electricity_trading/_client.py Added valid_only parameter to filter orders based on validity
tests/test_types.py Updated tests to use is_valid property instead of expecting exceptions

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


Raises:
ValueError: If the order price and quantity are not specified for a non-canceled order.
"""

Copilot AI Aug 15, 2025

Copy link

Choose a reason for hiding this comment

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

The docstring should be updated to mention that invalid orders are now supported and describe when an order is considered invalid.

Copilot uses AI. Check for mistakes.
tag: The tag to filter by.
page_size: The number of orders to return per page.
timeout: Timeout duration, defaults to None.
valid_only: If True, only returns orders that are valid.

Copilot AI Aug 15, 2025

Copy link

Choose a reason for hiding this comment

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

The parameter documentation should explain what makes an order valid or invalid (e.g., 'If True, only returns orders with finite price and quantity, unless they are cancelled').

Suggested change
valid_only: If True, only returns orders that are valid.
valid_only: If True, only returns orders with finite price and quantity, unless they are cancelled. If False, returns all orders regardless of validity.

Copilot uses AI. Check for mistakes.

@property
def is_valid(self) -> bool:
"""Check if the order detail is valid.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The docs should tell what is considered as a valid order.

tag: str | None = None,
page_size: int | None = None,
timeout: timedelta | None = None,
valid_only: bool = True,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Having the check only in this function is not sufficient, since there are other methods using OrderDetail. I wonder if from_pb method should keep the validation check but only raise if this flag is true.

@github-actions github-actions Bot added the part:docs Affects the documentation label Aug 15, 2025
@cwasicki

Copy link
Copy Markdown
Collaborator Author

Decided to remove the check for now, see #180.

Rebased this PR on top of #180 adding a is_valid check only.

@cwasicki cwasicki marked this pull request as draft August 15, 2025 12:30
@cwasicki cwasicki changed the title Support listing invalid orders Add is_valid check to OrderDetail Aug 15, 2025
@matthias-wende-frequenz

Copy link
Copy Markdown
Contributor

After updating the docs and rebasing this is good to go. @cwasicki can you please take care of it?

@cwasicki cwasicki marked this pull request as ready for review January 5, 2026 21:02
@cwasicki

cwasicki commented Jan 5, 2026

Copy link
Copy Markdown
Collaborator Author

@matthias-wende-frequenz Updated

Can be used by the user to check the validity of an order, which is
currently defined as any order with a valid price and quantity, or in
cancelled state.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
@cwasicki cwasicki added this pull request to the merge queue Jan 16, 2026
Merged via the queue into frequenz-floss:v0.x.x with commit ef76dea Jan 16, 2026
5 checks passed
@cwasicki cwasicki deleted the valid branch January 16, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants