Repository navigation
Fixing Targeting Context Groups - #81
Merged
Merged
Conversation
Matthew Metcalf (mrm9084)
requested review from
Avani Gupta (avanigupta)
and
a balanced review from Copilot
November 10, 2026 21:22
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The public groups parameter now rejects previously valid typed sequence callers, while unchanged runtime storage makes the list[str] field annotation inaccurate for non-list inputs.
1 open issue
What changed in this PR
This PR updates TargetingContext to provide a fresh, mutable groups list when groups are omitted or None, with regression coverage for model behavior and feature evaluation.
Changes:
- Introduces a named-tuple base and custom constructor while preserving supplied list identity.
- Tests field defaults, read-only attributes, serialization, and tuple helpers.
- Verifies group mutation and default-list isolation in synchronous and asynchronous feature evaluation.
| File | Description |
|---|---|
tests/test_default_feature_flags.py |
Adds model regression tests and synchronous targeting checks. |
tests/test_default_feature_flags_async.py |
Adds asynchronous targeting checks for mutable, independent groups. |
featuremanagement/_models/_targeting_context.py |
Adds per-instance default groups lists through a custom constructor. |
Review effort: Balanced
Zhiyuan Liang (zhiyuanliang-ms)
approved these changes
Nov 10, 2026
Avani Gupta (avanigupta)
approved these changes
Nov 10, 2026
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.

Description
This pull request refactors the
TargetingContextmodel to improve safety and usability, especially around default values and mutability, and adds comprehensive tests to verify its behavior. The main changes are the introduction of a safer default for thegroupsfield, prevention of accidental shared mutable state, and thorough testing of these improvements.TargetingContext Model Improvements
TargetingContextto inherit from a new_TargetingContextTuplebase, and changed thegroupsfield fromSequence[str]tolist[str], ensuring each instance gets its own list and avoiding shared mutable defaults. The constructor now handlesgroups=Noneby creating a new empty list. (featuremanagement/_models/_targeting_context.pyL8-R44)Safety and Mutability
_field_defaultsdictionary and updated the constructor to ensure that default values for fields, especiallygroups, are handled safely and do not result in shared mutable lists between instances. (featuremanagement/_models/_targeting_context.pyL8-R44)Comprehensive Testing
test_default_feature_flags.pyto verify:_makeand_replacemaintain subclass type and data integrity.groupslists are independent and not shared. (tests/test_default_feature_flags.pyR8-R81)Integration Tests
groupslist after construction affects feature flag evaluation as expected, and that defaultgroupslists remain independent. ([1], [2])Please add an informative description that covers that changes made by the pull request and link all relevant issues.
Contribution checklist:
General Guidelines and Best Practices