feat(client): pre-flight 30-facility limit check + clearer docstrings (#10)#36
Merged
Conversation
The /data/facilities/ endpoint accepts at most 30 facility_code (or unit_code) items per request and returns 422 above that. Catch the overflow client-side so users get a plain OpenElectricityError before the round-trip, and document the cap on both get_facility_data docstrings. Refs #10
This was referenced May 26, 2026
Merged
nc9
added a commit
that referenced
this pull request
May 26, 2026
Covers 0.10.1 through 0.11.2 plus an Unreleased section for the 30-facility pre-flight check (#36). Same style as the typescript client's CHANGELOG.
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.
Refs #10
What
The `/data/facilities/` endpoint accepts at most 30 `facility_code` (or `unit_code`) items per request. Above that the server returns a 422 with a pydantic validation payload. We can do better client-side:
The error message tells the user the exact remedy:
```
facility_code accepts at most 30 codes per request; got 36.
Split into chunks of 30 or filter further.
```
Why not auto-chunk?
nc9's reply on #10 said this is a "mildly superficial limit ... long-term the plan is to open it up". Hardcoding a chunk loop now would couple the SDK to a number that's expected to move. A clear pre-flight error is the cheapest user-facing improvement without that coupling.
Tests
`tests/test_facility_list_limit.py` — 5 tests covering the helper directly, the sync public path, the async public path, and both `facility_code` and `unit_code` lists. All pass; signature-parity test still green.
Verified live
```python
c.get_facility_data(network_code='NEM', facility_code=[36 codes], ...)
OpenElectricityError: facility_code accepts at most 30 codes per request; got 36.
```
No network round-trip on overflow.