Skip to content

feat: Add segment types, segment metadata, identity override segments support - #198

Closed
khvn26 wants to merge 4 commits into
mainfrom
feat/identity-override-segments
Closed

feat: Add segment types, segment metadata, identity override segments support#198
khvn26 wants to merge 4 commits into
mainfrom
feat/identity-override-segments

Conversation

@khvn26

Copy link
Copy Markdown
Member

Closes#197.

This PR adds the following:

  • meta: dict[str, str] | None field to the Segment model. It's intended to be used by Core and Edge API to store data specific for their Flagsmith implementations, unrelated to the engine and SDKs.
  • A special "_$identity.identifier" string literal can be now assigned to SegmentCondition.property_ to make the engine match segment condition rules against the identity identifier.

@github-actions

github-actionsBot commented Dec 7, 2023

Copy link
Copy Markdown

FileCoverage
All files100%

Minimum allowed coverage is 100%

Generated by 🐒 cobertura-action against de8a1ba

@matthewelwellmatthewelwell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor comments but looks pretty clean on the whole.

IS_NOT_SET: ConditionOperator = "IS_NOT_SET"
IN: ConditionOperator = "IN"

SEGMENT_IDENTIFIER_PROPERTY_NAME: str = "_$identity.identifier"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of feel like we could generalise this to just the prefix? So e.g. _$identity.identity_uuid would also work? Maybe that's a bit YAGNI?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_$identity.identity_uuid would also work?

In the future, maybe we'll want it to. Maybe we'll have other entities participating in the matching, e.g. $_contexts.org.location.

name: str
rules: typing.List[SegmentRuleModel] = Field(default_factory=list)
feature_states: typing.List[FeatureStateModel] = Field(default_factory=list)
meta: typing.Optional[typing.Dict[str, str]] = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should be at least a typed dict? Maybe one for a little further down the line when we know exactly what we need in the meta dict?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's two reasons I don't want to impose a typed dict here yet:

  1. The metadata schema is not settled yet.
  2. The engine does not need this metadata, APIs do. It's on Core/Edge to maintain the schema (could be a common library, just not the engine.)

Comment threadtests/unit/segments/fixtures.py Outdated
)
segment_identity_override = SegmentModel(
id=7,
name="segment_identity_override",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about this being unique in someway, right? Should we illustrate that even in this test data?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines +167 to +170
meta={
"identity_identifier": identifier,
"type": "IDENTITY_OVERRIDE",
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add identity_uuid here too?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@matthewelwellmatthewelwell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khvn26 I think this PR is still valuable but probably needs some reworking to fit in with the changes we made to the data structures?

@khvn26

Copy link
Copy Markdown
MemberAuthor

Superseded by #220.

@khvn26khvn26 closed this Aug 18, 2025
khvn26 added a commit that referenced this pull request Apr 24, 2026
- Bump the engine-test-data submodule to pick up Flagsmith/engine-test-data#51
(a realistic 262-feature / 26-multivariate / segment-override test case
mirroring the #198 scenario) and consume it as the large-context
benchmark, dropping the synthetic local fixture.
- Exercise the `metadata` branch of the `get_flag_result_from_context`
wrapper by adding metadata to the existing parametrized test.
- Add a test for the `value == 100` recursive fallback on the new
two-key fast-path hasher.
Restores 100% coverage and keeps the realistic benchmark portable across
every SDK consuming engine-test-data, rather than living only in this
repo's Python tests.
beep boop
khvn26 added a commit that referenced this pull request Apr 24, 2026
- Bump the engine-test-data submodule to pick up Flagsmith/engine-test-data#51
(a realistic 262-feature / 26-multivariate / segment-override test case
mirroring the #198 scenario) and consume it as the large-context
benchmark, dropping the synthetic local fixture.
- Exercise the `metadata` branch of the `get_flag_result_from_context`
wrapper by adding metadata to the existing parametrized test.
- Add a test for the `value == 100` recursive fallback on the new
two-key fast-path hasher.
Restores 100% coverage and keeps the realistic benchmark portable across
every SDK consuming engine-test-data, rather than living only in this
repo's Python tests.
beep boop
Sign up for freeto 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.

Identity-targeted segment conditions

2 participants

@khvn26@matthewelwell