refactor: Migrate from is_context_in_segment to get_evaluation_result#6896
Open
refactor: Migrate from is_context_in_segment to get_evaluation_result#6896
is_context_in_segment to get_evaluation_result#6896Conversation
…1/5) In this PR, we migrate the two callers of the vendored `is_context_in_segment` wrapper to use flag-engine v10's public API `get_evaluation_result` directly. This is the first step towards removing the vendored Pydantic models in `util/engine_models/`. Changes: - `Identity.get_segments()` now builds an `EvaluationContext` via the new `map_environment_to_evaluation_context` mapper and evaluates all segments in a single `get_evaluation_result` call, replacing the per-segment loop through `is_context_in_segment`. - `SegmentSerializer.get_member()` in the webhook integration is updated similarly. - New mapper functions in `util/mappers/engine.py`: `map_environment_to_evaluation_context`, `map_segment_to_segment_context`, `map_rule_to_segment_rule`, and `map_condition_to_segment_condition` — constructing flag-engine TypedDicts directly from Django ORM models. TypeAdapters are used only for literal types (`RuleType`, `ConditionOperator`). - `SegmentEngineMetadata` TypedDict in `segments/types.py` carries the segment PK through evaluation metadata, enabling unambiguous matching of results back to Django `Segment` objects (necessary when segments share the same name). - Removed `map_engine_identity_to_context` (the environment-less evaluation context mapper) — no longer needed. - Unit tests for all new mappers with 100% diff coverage.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
Contributor
Docker builds report
|
Contributor
Playwright Test Results (oss - depot-ubuntu-latest-16)Details
|
Contributor
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
|
Contributor
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
|
Contributor
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
|
is_context_in_segment to get_evaluation_resultis_context_in_segment to get_evaluation_result
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6896 +/- ##
==========================================
- Coverage 98.34% 98.33% -0.01%
==========================================
Files 1335 1334 -1
Lines 49707 49694 -13
==========================================
- Hits 48882 48867 -15
- Misses 825 827 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
18 tasks
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.
Thanks for submitting a PR! Please check the boxes below:
docs/if required so people know about the feature.Changes
Closes #6669.
In this PR, we migrate the two callers of the vendored
is_context_in_segmentwrapper to use flag-engine v10's public APIget_evaluation_resultdirectly. This is the first step towards removing the vendored Pydantic models inutil/engine_models/.Changes:
Identity.get_segments()now builds anEvaluationContextvia the newmap_environment_to_evaluation_contextmapper and evaluates all segments in a singleget_evaluation_resultcall, replacing the per-segment loop throughis_context_in_segment.SegmentSerializer.get_member()in the webhook integration is updated similarly.New mapper functions in
util/mappers/engine.py:map_environment_to_evaluation_context,map_segment_to_segment_context,map_rule_to_segment_rule, andmap_condition_to_segment_condition— constructing flag-engine TypedDicts directly from Django ORM models. TypeAdapters are used only for literal types (RuleType,ConditionOperator).SegmentEngineMetadataTypedDict insegments/types.pycarries the segment PK through evaluation metadata, enabling unambiguous matching of results back to DjangoSegmentobjects (necessary when segments share the same name).Removed
map_engine_identity_to_context(the environment-less evaluation context mapper) — no longer needed.Removed
environments/identities/helpers.pyand its duplicateget_hashed_percentage_for_object_ids(0–1 range).features/models.pynow imports directly fromflag_engine.utils.hashing(0–100 range), eliminating the* 100multiplication. Percentage-split tests simplified to use deterministic threshold values (100for always-in-segment,0for never-in-segment) instead of computing hash values.How did you test this code?