Skip to content

feat(client): pre-flight 30-facility limit check + clearer docstrings (#10)#36

Merged
nc9 merged 1 commit into
mainfrom
feat/facility-list-preflight
May 26, 2026
Merged

feat(client): pre-flight 30-facility limit check + clearer docstrings (#10)#36
nc9 merged 1 commit into
mainfrom
feat/facility-list-preflight

Conversation

@nc9

@nc9 nc9 commented May 26, 2026

Copy link
Copy Markdown
Member

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:

  • new `_check_facility_list_limit()` helper that raises `OpenElectricityError` before sending the request when either list exceeds 30
  • wired into both `OEClient._async_get_facility_data` and `AsyncOEClient.get_facility_data` (the two execution paths)
  • docstrings on the two public `get_facility_data` methods now document the cap

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.

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
@nc9 nc9 merged commit 37d43a5 into main May 26, 2026
5 checks passed
@nc9 nc9 deleted the feat/facility-list-preflight branch May 26, 2026 00:40
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant