3434
3535EMPLOYEE_ROLES = ["employee" , "contractor" ]
3636IDENTIFIERS = ["user_id" , "device_id" , "canonical_url" ]
37-
37+ TYPE_STR_LOOKUP = {
38+ bool : "boolean" ,
39+ int : "integer" ,
40+ float : "float" ,
41+ str : "string" ,
42+ dict : "map"
43+ }
3844
3945class EventType (Enum ):
4046 EXPOSE = "expose"
@@ -706,7 +712,7 @@ def get_bool(self, feature_name: str, default: bool = False) -> bool:
706712
707713 :return: the boolean value of the dyanimc config if it is active/exists, :code:`default` parameter otherwise.
708714 """
709- return self ._get_dynamic_config_value (feature_name , default , ["boolean" ])
715+ return self ._get_dynamic_config_value (feature_name , default , [bool ])
710716
711717 def get_int (self , feature_name : str , default : int = 0 ) -> int :
712718 """Fetch a Dynamic Configuration of int type.
@@ -718,7 +724,7 @@ def get_int(self, feature_name: str, default: int = 0) -> int:
718724
719725 :return: the int value of the dyanimc config if it is active/exists, :code:`default` parameter otherwise.
720726 """
721- return self ._get_dynamic_config_value (feature_name , default , ["integer" ])
727+ return self ._get_dynamic_config_value (feature_name , default , [int ])
722728
723729 def get_float (self , feature_name : str , default : float = 0.0 ) -> float :
724730 """Fetch a Dynamic Configuration of float type.
@@ -730,7 +736,7 @@ def get_float(self, feature_name: str, default: float = 0.0) -> float:
730736
731737 :return: the float value of the dyanimc config if it is active/exists, :code:`default` parameter otherwise.
732738 """
733- return self ._get_dynamic_config_value (feature_name , default , [" float" , "integer" ])
739+ return self ._get_dynamic_config_value (feature_name , default , [float , int ])
734740
735741 def get_string (self , feature_name : str , default : str = "" ) -> str :
736742 """Fetch a Dynamic Configuration of string type.
@@ -742,7 +748,7 @@ def get_string(self, feature_name: str, default: str = "") -> str:
742748
743749 :return: the string value of the dyanimc config if it is active/exists, :code:`default` parameter otherwise.
744750 """
745- return self ._get_dynamic_config_value (feature_name , default , ["string" ])
751+ return self ._get_dynamic_config_value (feature_name , default , [str ])
746752
747753 def get_map (self , feature_name : str , default : Optional [dict ] = None ) -> Optional [dict ]:
748754 """Fetch a Dynamic Configuration of map type.
@@ -754,7 +760,7 @@ def get_map(self, feature_name: str, default: Optional[dict] = None) -> Optional
754760
755761 :return: the map value of the dyanimc config if it is active/exists, :code:`default` parameter otherwise.
756762 """
757- return self ._get_dynamic_config_value (feature_name , default , ["map" ])
763+ return self ._get_dynamic_config_value (feature_name , default , [dict ])
758764
759765 def get_all_dynamic_configs (self ) -> List [Dict [str , Any ]]:
760766 """Return a list of dynamic configuration dicts in this format:
@@ -796,23 +802,23 @@ def get_all_dynamic_configs(self) -> List[Dict[str, Any]]:
796802 ctx = self ._decider_context .to_dict ()
797803
798804 try :
799- all_decisions = self ._internal .all_values (ctx )
805+ values = self ._internal .all_values (ctx )
800806 except DeciderException as exc :
801807 logger .info (str (exc ))
802808 return []
803809
804810 parsed_configs = []
805811
806- for decision in all_decisions . values ():
807- parsed_configs .append (self ._decision_to_dc_dict ( decision ))
812+ for feature_name , val in values . items ():
813+ parsed_configs .append (self ._value_to_dc_dict ( feature_name , val ))
808814
809815 return parsed_configs
810816
811817 def _get_dynamic_config_value (
812818 self ,
813819 feature_name : str ,
814820 default : Any ,
815- dc_types : List [str ],
821+ dc_types : List [type ],
816822 ) -> Any :
817823 if self ._internal is None :
818824 logger .error ("rs_decider is None--did not initialize." )
@@ -829,16 +835,18 @@ def _get_dynamic_config_value(
829835 logger .info (str (exc ))
830836 return default
831837
832- if decision .value_type not in dc_types :
838+ value = decision .value
839+
840+ if type (value ) not in dc_types :
833841 return default
834842
835- return decision . value
843+ return value
836844
837- def _decision_to_dc_dict (self , decision : Decision ) -> Dict [str , Any ]:
845+ def _value_to_dc_dict (self , feature_name : str , value : Optional [ Any ] ) -> Dict [str , Any ]:
838846 return {
839- "name" : decision . feature_name ,
840- "value" : decision . value ,
841- "type" : decision . value_type or "" ,
847+ "name" : feature_name ,
848+ "value" : value ,
849+ "type" : "" if value is None else TYPE_STR_LOOKUP [ type ( value )] ,
842850 }
843851
844852 def get_experiment (self , experiment_name : str ) -> Optional [ExperimentConfig ]:
0 commit comments