@@ -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