Skip to content

Commit 4acf348

Browse files
committed
Fix unit and FSC tests
1 parent b3f17f1 commit 4acf348

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

optimizely/decision_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ def get_decision_for_flag(
708708
user_id = user_context.user_id
709709

710710
# Check holdouts
711-
holdouts = project_config.get_holdouts_for_flag(feature_flag.key)
711+
holdouts = project_config.get_holdouts_for_flag(feature_flag.id)
712712
for holdout in holdouts:
713713
holdout_decision = self.get_variation_for_holdout(holdout, user_context, project_config)
714714
reasons.extend(holdout_decision['reasons'])
@@ -907,7 +907,7 @@ def get_variation_for_holdout(
907907

908908
# Create Decision for holdout - pass holdout dict as experiment, source is HOLDOUT
909909
holdout_decision: Decision = Decision(
910-
experiment=holdout,
910+
experiment=None,
911911
variation=variation,
912912
source=enums.DecisionSources.HOLDOUT,
913913
cmab_uuid=None

optimizely/optimizely.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from typing import TYPE_CHECKING, Any, Optional, Union
1717

18-
from optimizely.helpers.types import VariationDict
18+
from optimizely.helpers.types import HoldoutDict, VariationDict
1919

2020

2121
from . import decision_service
@@ -261,10 +261,10 @@ def _get_feature_enabled(self, variation: Optional[Union[entities.Variation, Var
261261
except (AttributeError, KeyError, TypeError):
262262
return False
263263

264-
def _get_experiment_key(self, experiment: Optional[Union[entities.Experiment, dict]]) -> Optional[str]:
264+
def _get_experiment_key(self, experiment: Optional[Union[entities.Experiment, HoldoutDict]]) -> Optional[str]:
265265
"""Helper to extract experiment/holdout key from either dict or Experiment object.
266266
Args:
267-
experiment: Either a dict (from holdout) or entities.Experiment object
267+
experiment: Either a HoldoutDict (from holdout) or entities.Experiment object
268268
Returns:
269269
The experiment/holdout key as a string, or None if not available
270270
"""

optimizely/project_config.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -833,12 +833,12 @@ def get_flag_variation(
833833

834834
return None
835835

836-
def get_holdouts_for_flag(self, flag_key: str) -> list[HoldoutDict]:
836+
def get_holdouts_for_flag(self, flag_key_or_id: str) -> list[HoldoutDict]:
837837
""" Helper method to get holdouts from an applied feature flag.
838838
839839
Args:
840-
flag_key: Key of the feature flag.
841-
This parameter is required and should not be null/None.
840+
flag_key_or_id: Key or ID of the feature flag.
841+
This parameter is required and should not be null/None.
842842
843843
Returns:
844844
The holdouts that apply for a specific flag.
@@ -847,18 +847,21 @@ def get_holdouts_for_flag(self, flag_key: str) -> list[HoldoutDict]:
847847
return []
848848

849849
# Check cache first (before validation, so we cache the validation result too)
850-
if flag_key in self.flag_holdouts_map:
851-
return self.flag_holdouts_map[flag_key]
850+
if flag_key_or_id in self.flag_holdouts_map:
851+
return self.flag_holdouts_map[flag_key_or_id]
852852

853-
# Validate that the flag exists in the datafile
854-
feature = self.feature_key_map.get(flag_key)
855-
if not feature:
853+
# Find the flag by key or ID
854+
flag_id = None
855+
for flag in self.feature_flags:
856+
if flag['id'] == flag_key_or_id or flag['key'] == flag_key_or_id:
857+
flag_id = flag['id']
858+
break
859+
860+
if flag_id is None:
856861
# Cache the empty result for non-existent flags
857-
self.flag_holdouts_map[flag_key] = []
862+
self.flag_holdouts_map[flag_key_or_id] = []
858863
return []
859864

860-
flag_id = feature.id
861-
862865
# Prioritize global holdouts first
863866
excluded = self.excluded_holdouts.get(flag_id, [])
864867

@@ -875,10 +878,10 @@ def get_holdouts_for_flag(self, flag_key: str) -> list[HoldoutDict]:
875878
included = self.included_holdouts.get(flag_id, [])
876879
active_holdouts.extend(included)
877880

878-
# Cache the result
879-
self.flag_holdouts_map[flag_key] = active_holdouts
881+
# Cache the result using the input parameter as the cache key
882+
self.flag_holdouts_map[flag_key_or_id] = active_holdouts
880883

881-
return self.flag_holdouts_map[flag_key]
884+
return self.flag_holdouts_map[flag_key_or_id]
882885

883886
def get_holdout(self, holdout_id: str) -> Optional[HoldoutDict]:
884887
""" Helper method to get holdout from holdout ID.

0 commit comments

Comments
 (0)