@@ -704,7 +704,7 @@ def is_feature_enabled(self, feature_key: str, user_id: str, attributes: Optiona
704
704
if (is_source_rollout or not decision .variation ) and project_config .get_send_flag_decisions_value ():
705
705
self ._send_impression_event (
706
706
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
708
708
)
709
709
710
710
# 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
715
715
}
716
716
self ._send_impression_event (
717
717
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
719
719
)
720
720
721
721
if feature_enabled :
@@ -1133,18 +1133,13 @@ def _decide(
1133
1133
1134
1134
return decision
1135
1135
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
-
1141
1136
def _create_optimizely_decision (
1142
1137
self ,
1143
- user_context : Optional [ OptimizelyUserContext ] ,
1138
+ user_context : OptimizelyUserContext ,
1144
1139
flag_key : str ,
1145
- flag_decision : Optional [ Decision ] ,
1140
+ flag_decision : Decision ,
1146
1141
decision_reasons : Optional [list [str ]],
1147
- decide_options : Optional [ list [OptimizelyDecideOption ] ],
1142
+ decide_options : list [str ],
1148
1143
project_config : ProjectConfig
1149
1144
) -> OptimizelyDecision :
1150
1145
user_id = user_context .user_id
@@ -1164,30 +1159,18 @@ def _create_optimizely_decision(
1164
1159
1165
1160
feature_flag = project_config .feature_key_map .get (flag_key )
1166
1161
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
-
1179
1162
# Send impression event if Decision came from a feature
1180
1163
# test and decide options doesn't include disableDecisionEvent
1181
1164
if OptimizelyDecideOption .DISABLE_DECISION_EVENT not in decide_options :
1182
1165
if decision_source == DecisionSources .FEATURE_TEST or project_config .send_flag_decisions :
1183
1166
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 ,
1185
1168
user_id , attributes )
1186
1169
1187
1170
decision_event_dispatched = True
1188
1171
1189
1172
# 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 :
1191
1174
for variable_key , variable in feature_flag .variables .items ():
1192
1175
variable_value = variable .defaultValue
1193
1176
if feature_enabled :
@@ -1301,7 +1284,7 @@ def _decide_for_keys(
1301
1284
1302
1285
enabled_flags_only = OptimizelyDecideOption .ENABLED_FLAGS_ONLY in merged_decide_options
1303
1286
1304
- decisions = {}
1287
+ decisions : dict [ str , OptimizelyDecision ] = {}
1305
1288
valid_keys = []
1306
1289
decision_reasons_dict = {}
1307
1290
# for key in keys:
@@ -1314,14 +1297,15 @@ def _decide_for_keys(
1314
1297
flags_without_forced_decision : list [entities .FeatureFlag ] = []
1315
1298
flag_decisions : dict [str , Decision ] = {}
1316
1299
1317
-
1300
+ if project_config is None :
1301
+ return decisions
1318
1302
for key in keys :
1319
1303
feature_flag = project_config .feature_key_map .get (key )
1320
1304
if feature_flag is None :
1321
1305
decisions [key ] = OptimizelyDecision (None , False , None , None , key , user_context , [])
1322
1306
continue
1323
1307
valid_keys .append (key )
1324
- decision_reasons = []
1308
+ decision_reasons : list [ str ] = []
1325
1309
decision_reasons_dict [key ] = decision_reasons
1326
1310
1327
1311
optimizely_decision_context = OptimizelyUserContext .OptimizelyDecisionContext (flag_key = key , rule_key = None )
@@ -1360,7 +1344,6 @@ def _decide_for_keys(
1360
1344
for key in valid_keys :
1361
1345
flag_decision = flag_decisions [key ]
1362
1346
decision_reasons = decision_reasons_dict [key ]
1363
- decision_reasons = self ._fix_nested_decision_reasons_list (decision_reasons )
1364
1347
optimizely_decision = self ._create_optimizely_decision (
1365
1348
user_context ,
1366
1349
key ,
0 commit comments