Skip to content

Validate the arguments of every public method with probatio - #1597

Merged
frenck merged 1 commit into
mainfrom
frenck/probatio
Oct 2, 2026
Merged

frenck merged 1 commit into
mainfrom
frenck/probatio

Conversation

@frenck

@frenck frenck commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Breaking change

Invalid arguments now raise probatio.Invalid (or its subclass MultipleInvalid) instead of a ValueError. Code that catches ValueError around radios calls should catch probatio.Invalid instead. Home Assistant does not catch either.

Arguments are now also checked for their type, so a call like station(uuid=42) or tags(limit="ten") is refused before a request is sent.

Proposed change

Moves argument validation to probatio, which Home Assistant itself now uses instead of voluptuous.

Every public method that takes arguments gets the @probatio decorator, and its rules live next to the parameters, as Annotated validators:

  • Count (NonNegative()) for limit, offset, seconds and the bitrates
  • ListOrder and StationOrder (In(...)) for the orders each kind of endpoint supports
  • In(SEARCH_FILTERS) for the filter_by values search() can express
  • Latitude(), Longitude() and NonNegative() for a geo search

That replaces the hand written validate_order() and validate_paging(). Rules that span several arguments (a latitude needs a longitude, filter_by needs a filter_term) stay in the method bodies, and raise Invalid as well, so one except probatio.Invalid covers every invalid argument.

The coordinate validation fixes a finding of a fourth review round: search(geo_lat=91, ...) was sent to the API, which answers out of range coordinates with a server error (checked live: HTTP 500), retried five times. It now fails right away:

probatio.MultipleInvalid: value must be at most 90 at 'geo_lat'

The dependency is probatio>=0.12.4, the version Home Assistant pins; everything used here is in that release. The README and AGENTS.md describe the new error.

Type of change

  • Dependency or tooling upgrade
  • Bugfix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Deprecation (replaces or removes a feature, with a migration path)
  • Breaking change (a fix or feature that changes existing behavior)
  • Code quality, refactor, or test-only change
  • Documentation only

Additional information

  • This PR fixes or closes issue: fixes # None
  • This PR is related to: None
  • Link to a separate documentation pull request: None

Checklist

  • I fully understand the code in this pull request and can explain every line, including any AI-assisted changes.
  • The change is covered by tests, and poetry run pytest passes locally. A pull request cannot be merged unless CI is green.
  • poetry run prek run --all-files passes (lint, format, and type checks).
  • No commented-out or dead code is left in the pull request.

Replace the hand written order and paging checks with the probatio
decorator and Annotated validators on the parameters. This also validates
the coordinates of a geo search, which the API answers with a server error
when they are out of range, and the types of every argument. Invalid
arguments now raise probatio.Invalid instead of a ValueError.
@frenck frenck added the breaking-change A breaking change for existing users. label Oct 2, 2026
@frenck
frenck merged commit 5c4c087 into main Oct 2, 2026
31 checks passed
@frenck
frenck deleted the frenck/probatio branch October 2, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change A breaking change for existing users.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant