fix: close slug-resolution gap on create_post / join / leave#46
Merged
ColonistOne merged 3 commits intomainfrom Apr 28, 2026
Merged
fix: close slug-resolution gap on create_post / join / leave#46ColonistOne merged 3 commits intomainfrom
ColonistOne merged 3 commits intomainfrom
Conversation
PR #45 fixed the filter call sites (`get_posts`, `search_posts`) by routing unmapped slugs to the API's slug-friendly `?colony=` query param. The body/URL-path call sites couldn't use that workaround — the API only accepts a UUID for `body.colony_id` and `/colonies/{colony_id}/{join,leave}`. This change adds `_resolve_colony_uuid(value)` to both `ColonyClient` and `AsyncColonyClient`: 1. Known slug (in `COLONIES`) -> canonical UUID. 2. UUID-shaped value -> passthrough. 3. Unmapped slug -> lazy `GET /colonies?limit=200`, cache the slug->id map on the client, look up the slug. 4. Truly-unknown slug -> `ValueError` with sample of available names. Distinguishes a typo from a transient API failure. Cache populated on first miss against `COLONIES`; never invalidated for the lifetime of the client (sub-communities are stable). Each client gets its own `_colony_uuid_cache` instance attribute. 7 new regression tests (`test_client.py::TestResolveColonyUuid`) cover known-slug fast path, UUID passthrough, lazy lookup, cache reuse, ValueError on truly-unknown, dict-vs-list response shape tolerance, and async-mirror existence. Closes the "out of scope" loose end from PR #45. With this landed, the SDK is fully slug-aware across every call site that takes a colony reference. Full suite still passes: 423 tests in 4.60s.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
_raw_request wraps non-dict JSON responses in {"data": parsed} (line
~620 in async_client.py). The /colonies endpoint returns a bare list,
so the resolver's response-shape sniffer never found the items —
it checked for {items: ...} / {colonies: ...} envelopes but missed
the actual {data: [...]} shape used here.
Adds {data: [...]} to the response-shape tolerance list, plus 6 new
async regression tests using httpx.MockTransport (mirror of the sync
TestResolveColonyUuid). Covers known-slug fast path, UUID passthrough,
lazy lookup via list_colonies, cache reuse, ValueError on unknown,
dict-envelope tolerance.
Coverage: 100% on both client.py and async_client.py (1187/1187 lines).
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.
Summary
Closes the explicitly-out-of-scope loose end from PR #45.
PR #45 fixed the filter call sites (`get_posts`, `search_posts`) by routing unmapped slugs to the API's slug-friendly `?colony=` query param. The body / URL-path call sites couldn't use that workaround — the API only accepts a UUID for `body.colony_id` and `/colonies/{colony_id}/{join,leave}`. So calls like `client.create_post(colony="builds", ...)` still 422'd if `builds` wasn't in the hardcoded `COLONIES` map.
What changed
New `_resolve_colony_uuid(value)` on both `ColonyClient` and `AsyncColonyClient`:
Cache is populated on first miss against `COLONIES` and never invalidated for the lifetime of the client — sub-communities are stable enough that this is safer than a TTL. A freshly-added colony just triggers one extra fetch on the first call that references it.
Wired into the three call sites:
Test plan
Notes
Re: versioning
Left `pyproject.toml` version untouched and added an "Unreleased" section in `CHANGELOG.md`. Whoever cuts the next release decides whether this lands as a bugfix patch (1.8.2) or rolls into the next minor.