-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Context values for Segments #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b931a04
use test data
khvn26 53e55f6
feat: Context values for Segments
khvn26 7f0f21c
fix coverage
khvn26 42829fa
restore `override_traits` behaviour
khvn26 93418fd
`TraitValue` -> `ContextValue`
khvn26 1bf3d0d
fix itemgetters
khvn26 2156fed
improve docs
khvn26 c6b172b
formatting
khvn26 41bdaca
fix test data
khvn26 e43ff95
improve naming
khvn26 58e833a
fix typing
khvn26 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [submodule "tests/engine_tests/engine-test-data"] | ||
| path = tests/engine_tests/engine-test-data | ||
| url = https://github.com/flagsmith/engine-test-data.git | ||
| branch = feat/context-values | ||
Empty file.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from flag_engine.context.types import EvaluationContext | ||
| from flag_engine.environments.models import EnvironmentModel | ||
| from flag_engine.identities.models import IdentityModel | ||
|
|
||
|
|
||
| def map_environment_identity_to_context( | ||
| environment: EnvironmentModel, | ||
| identity: IdentityModel, | ||
| ) -> EvaluationContext: | ||
| """ | ||
| Maps an EnvironmentModel and IdentityModel to an EvaluationContext. | ||
| :param environment: The environment model object. | ||
| :param identity: The identity model object. | ||
| :return: An EvaluationContext containing the environment and identity. | ||
matthewelwell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
| return { | ||
| "environment": { | ||
| "key": environment.api_key, | ||
| "name": environment.name or "", | ||
| }, | ||
| "identity": { | ||
| "identifier": identity.identifier, | ||
| "key": str(identity.django_id or identity.composite_key), | ||
| "traits": { | ||
| trait.trait_key: trait.trait_value for trait in identity.identity_traits | ||
| }, | ||
| }, | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # generated by datamodel-codegen: | ||
| # filename: https://raw.githubusercontent.com/Flagsmith/flagsmith/chore/update-evaluation-context/sdk/evaluation-context.json # noqa: E501 | ||
| # timestamp: 2025-07-16T10:39:10+00:00 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Dict, Optional, TypedDict | ||
|
|
||
| from typing_extensions import NotRequired | ||
|
|
||
| from flag_engine.identities.traits.types import TraitValue | ||
| from flag_engine.utils.types import SupportsStr | ||
|
|
||
|
|
||
| class EnvironmentContext(TypedDict): | ||
| key: str | ||
| name: str | ||
|
|
||
|
|
||
| class IdentityContext(TypedDict): | ||
| identifier: str | ||
| key: SupportsStr | ||
| traits: NotRequired[Dict[str, TraitValue]] | ||
|
|
||
|
|
||
| class EvaluationContext(TypedDict): | ||
| environment: EnvironmentContext | ||
| identity: NotRequired[Optional[IdentityContext]] | ||
emyller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reminder to delete.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A discussion point as well as merging Flagsmith/engine-test-data#8 will break CI for all local eval SDKs. It's a good incentive for closing Flagsmith/flagsmith#5676 ASAP, of course, but perhaps we should consider versioning
engine-test-data.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean hard versions? e.g.
v1/andv2/, etc? I support temporary branch pointing atmain— given a reasonable plan — unless there's value in the former.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant using version tags in engine-test-data and referencing them instead of main branch in submodules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Yes, I think it makes sense to version the test data.
I guess the original thinking behind not versioning it, is that the test data was to be used for more of a regression test, but I don't think that makes sense here, so I'm happy to go with a versioned approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created https://github.com/Flagsmith/engine-test-data/releases/tag/v1.0.0 for the current SDKs to point to 👍