feat: Add GetFeatureByName and GetSegmentByName - #22
Closed
matthewelwell wants to merge 1 commit into
Closed
Conversation
This was referenced Aug 25, 2026
matthewelwell
marked this pull request as draft
August 25, 2026 16:49
matthewelwell
force-pushed
the
feat/lookup-features-and-segments-by-name
branch
from
August 25, 2026 17:20
0055c7c to
7cca891
Compare
Adds lookups by name for features and segments, so that callers which know a project UUID and a name -- but not a UUID -- can resolve an entity. This is what the Terraform provider needs to offer `flagsmith_feature` and `flagsmith_segment` data sources. Two things about the API are worth knowing: - Features filter on `search`, segments filter on `q`. Passing the wrong one is silently ignored and returns every result in the project. - Both filters are case insensitive "contains" matches, so results have to be filtered client side for an exact match. Without that, asking for `flag` could return `flagship`. Each lookup is a single request. CustomPagination allows at most 999 results per page, which is sent explicitly so that a change to the API's default page size cannot silently truncate a search. A truncated page means an exact match may have been missed, so that returns an error rather than a false "not found"; it takes a project with more than 999 entities whose names all contain the search term to reach. Segment names are not unique within a project, so a name that matches more than one segment returns MultipleSegmentsFoundError rather than picking arbitrarily. Feature names are uniquely indexed, so the equivalent feature error is defensive only. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
matthewelwell
force-pushed
the
feat/lookup-features-and-segments-by-name
branch
from
August 25, 2026 17:32
7cca891 to
b617e75
Compare
Contributor
Author
|
Superseded: the Terraform provider data sources are now keyed on Lookup by name is still a reasonable addition if it's wanted later — the branch is kept for reference. The two API details it dealt with are worth recording either way: features filter on |
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.
Adds lookups by name for features and segments, so callers that know a project UUID and a name — but not a UUID — can resolve an entity.
This unblocks terraform-provider-flagsmith#153, which asks for
flagsmith_featureandflagsmith_segmentdata sources so that features created outside of Terraform can be referenced.Things worth knowing about the API
Both are built on a shared
searchProjectResourceshelper, because two API details make this less trivial than it looks:search, segments filter onq. Passing the wrong param is silently ignored and returns every result in the project.containsmatches, so results have to be filtered client-side for an exact match. Without that, asking forflagcould resolve toflagship.Pages are requested as
page=Nagainst the client's configured base URL rather than by following DRF'snextlink, which is built from the incoming request host and so can be unreachable behind a self-hosted reverse proxy.nextis used only as a "there is more" signal.ProjectUUIDis set from the argument, since the API never returns it. The Terraform provider depends on this: a data source read whose required attributes don't echo the configuration is rejected by Terraform core.Duplicate names
Segment names are not unique within a project (
Segment.Metahas no constraint), so a name matching more than one segment returnsMultipleSegmentsFoundErrorrather than picking arbitrarily. Feature names are uniquely indexed, soMultipleFeaturesFoundErroris defensive only — but it fails loudly rather than silently choosing a row if that invariant ever changes.Tests
19 new unit tests in
search_test.gocovering exact-match filtering, partial-match-only, case sensitivity, pagination, duplicate matches, API errors, an unresolvable project, the segment rules tree, feature-specific segments, and that thesearch/qparams andProjectUUIDstamping are correct. No existing behaviour changes.Release
Needs a v0.12.0 tag once merged, so the Terraform provider can depend on it.
🤖 Generated with Claude Code