-
Notifications
You must be signed in to change notification settings - Fork 36
[AI-FSSDK] [FSSDK-12369] Add local holdouts support to Python SDK #512
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
FarhanAnjum-opti
merged 5 commits into
master
from
ai/mat001/FSSDK-12369-local-holdouts-2
Jun 1, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fdcb27d
[AI-FSSDK] [FSSDK-12369] Add local holdouts support to Python SDK
Mat001 65e390c
[FSSDK-12369] Fix copyright year from 2025 to 2026 in new test files
Mat001 0d6e3ad
[FSSDK-12369] Add mandatory forced-decision-beats-local-holdout enfor…
Mat001 7cb671b
trigger CI
Mat001 a2bdaa3
trigger CI
FarhanAnjum-opti 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
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 |
|---|---|---|
|
|
@@ -223,6 +223,7 @@ def __init__( | |
| trafficAllocation: list[TrafficAllocation], | ||
| audienceIds: list[str], | ||
| audienceConditions: Optional[Sequence[str | list[str]]] = None, | ||
| includedRules: Optional[list[str]] = None, | ||
| **kwargs: Any | ||
| ): | ||
| self.id = id | ||
|
|
@@ -232,6 +233,8 @@ def __init__( | |
| self.trafficAllocation = trafficAllocation | ||
| self.audienceIds = audienceIds | ||
| self.audienceConditions = audienceConditions | ||
| # None = global holdout (applies to all rules); list of rule IDs = local holdout | ||
| self.included_rules: Optional[list[str]] = includedRules | ||
|
|
||
| def get_audience_conditions_or_ids(self) -> Sequence[str | list[str]]: | ||
| """Returns audienceConditions if present, otherwise audienceIds. | ||
|
|
@@ -241,6 +244,18 @@ def get_audience_conditions_or_ids(self) -> Sequence[str | list[str]]: | |
| """ | ||
| return self.audienceConditions if self.audienceConditions is not None else self.audienceIds | ||
|
|
||
| @property | ||
| def is_global(self) -> bool: | ||
| """Check if this is a global holdout (applies to all rules across all flags). | ||
|
|
||
| A holdout is global when includedRules is None (absent from datafile). | ||
| An empty list [] is a local holdout that targets no rules (different from global). | ||
|
|
||
| Returns: | ||
| True if included_rules is None (global), False otherwise (local). | ||
| """ | ||
| return self.included_rules is None | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good |
||
|
|
||
| @property | ||
| def is_activated(self) -> bool: | ||
| """Check if the holdout is activated (running). | ||
|
|
||
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
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 |
|---|---|---|
|
|
@@ -93,7 +93,10 @@ def __init__(self, datafile: str | bytes, logger: Logger, error_handler: Any): | |
| holdouts_data: list[types.HoldoutDict] = config.get('holdouts', []) | ||
| self.holdouts: list[entities.Holdout] = [] | ||
| self.holdout_id_map: dict[str, entities.Holdout] = {} | ||
| self.flag_holdouts_map: dict[str, list[entities.Holdout]] = {} | ||
| # Global holdouts (includedRules is None) — evaluated at flag level before any rule | ||
| self.global_holdouts: list[entities.Holdout] = [] | ||
| # Rule-level holdouts — map from rule ID to holdouts targeting that rule | ||
| self.rule_holdouts_map: dict[str, list[entities.Holdout]] = {} | ||
|
|
||
| # Convert holdout dicts to Holdout entities | ||
| for holdout_data in holdouts_data: | ||
|
|
@@ -108,6 +111,16 @@ def __init__(self, datafile: str | bytes, logger: Logger, error_handler: Any): | |
| # Map by ID for quick lookup | ||
| self.holdout_id_map[holdout.id] = holdout | ||
|
|
||
| # Classify holdout as global or local based on includedRules | ||
| if holdout.is_global: | ||
| self.global_holdouts.append(holdout) | ||
| else: | ||
| # Local holdout — register for each targeted rule ID | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good |
||
| for rule_id in (holdout.included_rules or []): | ||
| if rule_id not in self.rule_holdouts_map: | ||
| self.rule_holdouts_map[rule_id] = [] | ||
| self.rule_holdouts_map[rule_id].append(holdout) | ||
|
|
||
| # Utility maps for quick lookup | ||
| self.group_id_map: dict[str, entities.Group] = self._generate_key_map(self.groups, 'id', entities.Group) | ||
| self.experiment_id_map: dict[str, entities.Experiment] = self._generate_key_map( | ||
|
|
@@ -240,11 +253,6 @@ def __init__(self, datafile: str | bytes, logger: Logger, error_handler: Any): | |
| everyone_else_variation.variables, 'id', entities.Variation.VariableUsage | ||
| ) | ||
|
|
||
| # Map all running holdouts to this flag | ||
| applicable_holdouts = list(self.holdout_id_map.values()) | ||
| if applicable_holdouts: | ||
| self.flag_holdouts_map[feature.key] = applicable_holdouts | ||
|
|
||
| rollout = None if len(feature.rolloutId) == 0 else self.rollout_id_map[feature.rolloutId] | ||
| if rollout: | ||
| for exp in rollout.experiments: | ||
|
|
@@ -878,19 +886,30 @@ def get_flag_variation( | |
|
|
||
| return None | ||
|
|
||
| def get_holdouts_for_flag(self, flag_key: str) -> list[entities.Holdout]: | ||
| """ Helper method to get holdouts from an applied feature flag. | ||
| def get_global_holdouts(self) -> list[entities.Holdout]: | ||
| """Return all global holdouts (includedRules is None). | ||
|
|
||
| Args: | ||
| flag_key: Key of the feature flag. | ||
| Global holdouts are evaluated at flag level before any rule is checked. | ||
|
|
||
| Returns: | ||
| The holdouts that apply for a specific flag as Holdout entity objects. | ||
| List of global Holdout entities that are currently running. | ||
| """ | ||
| if not self.holdouts: | ||
| return [] | ||
| return self.global_holdouts | ||
|
|
||
| def get_holdouts_for_rule(self, rule_id: str) -> list[entities.Holdout]: | ||
| """Return local holdouts that target a specific rule. | ||
|
|
||
| return self.flag_holdouts_map.get(flag_key, []) | ||
| Local holdouts are evaluated per-rule, before the rule's audience and | ||
| traffic allocation checks. A rule ID not present in any holdout's | ||
| includedRules simply returns an empty list — silently skipped. | ||
|
|
||
| Args: | ||
| rule_id: The experiment or delivery rule ID to look up. | ||
|
|
||
| Returns: | ||
| List of local Holdout entities targeting the given rule ID. | ||
| """ | ||
| return self.rule_holdouts_map.get(rule_id, []) | ||
|
|
||
| def get_holdout(self, holdout_id: str) -> Optional[entities.Holdout]: | ||
| """ Helper method to get holdout from holdout ID. | ||
|
|
||
Oops, something went wrong.
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.
Looks good