@@ -704,7 +704,7 @@ def is_feature_enabled(self, feature_key: str, user_id: str, attributes: Optiona
704704 if (is_source_rollout or not decision .variation ) and project_config .get_send_flag_decisions_value ():
705705 self ._send_impression_event (
706706 project_config , decision .experiment , decision .variation , feature .key , decision .experiment .key if
707- decision .experiment else '' , decision .source , feature_enabled , user_id , attributes
707+ decision .experiment else '' , str ( decision .source ) , feature_enabled , user_id , attributes
708708 )
709709
710710 # Send event if Decision came from an experiment.
@@ -715,7 +715,7 @@ def is_feature_enabled(self, feature_key: str, user_id: str, attributes: Optiona
715715 }
716716 self ._send_impression_event (
717717 project_config , decision .experiment , decision .variation , feature .key , decision .experiment .key ,
718- decision .source , feature_enabled , user_id , attributes
718+ str ( decision .source ) , feature_enabled , user_id , attributes
719719 )
720720
721721 if feature_enabled :
@@ -1133,18 +1133,13 @@ def _decide(
11331133
11341134 return decision
11351135
1136- def _fix_nested_decision_reasons_list (self , decision_reasons )-> list :
1137- if len (decision_reasons )== 1 and type (decision_reasons [0 ])== type (list ()):
1138- decision_reasons = decision_reasons [0 ]
1139- return decision_reasons
1140-
11411136 def _create_optimizely_decision (
11421137 self ,
1143- user_context : Optional [ OptimizelyUserContext ] ,
1138+ user_context : OptimizelyUserContext ,
11441139 flag_key : str ,
1145- flag_decision : Optional [ Decision ] ,
1140+ flag_decision : Decision ,
11461141 decision_reasons : Optional [list [str ]],
1147- decide_options : Optional [ list [OptimizelyDecideOption ] ],
1142+ decide_options : list [str ],
11481143 project_config : ProjectConfig
11491144 ) -> OptimizelyDecision :
11501145 user_id = user_context .user_id
@@ -1164,30 +1159,18 @@ def _create_optimizely_decision(
11641159
11651160 feature_flag = project_config .feature_key_map .get (flag_key )
11661161
1167- # Fill in experiment and variation if returned (rollouts can have featureEnabled variables as well.)
1168- # if flag_decision.experiment is not None:
1169- # experiment = flag_decision.experiment
1170- # source_info["experiment"] = experiment
1171- # rule_key = experiment.key if experiment else None
1172- # if flag_decision.variation is not None:
1173- # variation = flag_decision.variation
1174- # variation_key = variation.key
1175- # feature_enabled = variation.featureEnabled
1176- # decision_source = decision.source
1177- # source_info["variation"] = variation
1178-
11791162 # Send impression event if Decision came from a feature
11801163 # test and decide options doesn't include disableDecisionEvent
11811164 if OptimizelyDecideOption .DISABLE_DECISION_EVENT not in decide_options :
11821165 if decision_source == DecisionSources .FEATURE_TEST or project_config .send_flag_decisions :
11831166 self ._send_impression_event (project_config , flag_decision .experiment , flag_decision .variation , flag_key , rule_key or '' ,
1184- decision_source , feature_enabled ,
1167+ str ( decision_source ) , feature_enabled ,
11851168 user_id , attributes )
11861169
11871170 decision_event_dispatched = True
11881171
11891172 # Generate all variables map if decide options doesn't include excludeVariables
1190- if OptimizelyDecideOption .EXCLUDE_VARIABLES not in decide_options :
1173+ if OptimizelyDecideOption .EXCLUDE_VARIABLES not in decide_options and feature_flag :
11911174 for variable_key , variable in feature_flag .variables .items ():
11921175 variable_value = variable .defaultValue
11931176 if feature_enabled :
@@ -1301,7 +1284,7 @@ def _decide_for_keys(
13011284
13021285 enabled_flags_only = OptimizelyDecideOption .ENABLED_FLAGS_ONLY in merged_decide_options
13031286
1304- decisions = {}
1287+ decisions : dict [ str , OptimizelyDecision ] = {}
13051288 valid_keys = []
13061289 decision_reasons_dict = {}
13071290 # for key in keys:
@@ -1314,14 +1297,15 @@ def _decide_for_keys(
13141297 flags_without_forced_decision : list [entities .FeatureFlag ] = []
13151298 flag_decisions : dict [str , Decision ] = {}
13161299
1317-
1300+ if project_config is None :
1301+ return decisions
13181302 for key in keys :
13191303 feature_flag = project_config .feature_key_map .get (key )
13201304 if feature_flag is None :
13211305 decisions [key ] = OptimizelyDecision (None , False , None , None , key , user_context , [])
13221306 continue
13231307 valid_keys .append (key )
1324- decision_reasons = []
1308+ decision_reasons : list [ str ] = []
13251309 decision_reasons_dict [key ] = decision_reasons
13261310
13271311 optimizely_decision_context = OptimizelyUserContext .OptimizelyDecisionContext (flag_key = key , rule_key = None )
@@ -1360,7 +1344,6 @@ def _decide_for_keys(
13601344 for key in valid_keys :
13611345 flag_decision = flag_decisions [key ]
13621346 decision_reasons = decision_reasons_dict [key ]
1363- decision_reasons = self ._fix_nested_decision_reasons_list (decision_reasons )
13641347 optimizely_decision = self ._create_optimizely_decision (
13651348 user_context ,
13661349 key ,
0 commit comments