@@ -46,7 +46,7 @@ def __init__(self, optimizely_client, user_id, user_attributes=None):
46
46
47
47
self ._user_attributes = user_attributes .copy () if user_attributes else {}
48
48
self .lock = threading .Lock ()
49
- self .forced_decisions = {}
49
+ self .forced_decisions_map = {}
50
50
self .log = logger .SimpleLogger (min_level = enums .LogLevels .INFO )
51
51
52
52
# decision context
@@ -73,8 +73,8 @@ def _clone(self):
73
73
user_context = OptimizelyUserContext (self .client , self .user_id , self .get_user_attributes ())
74
74
75
75
with self .lock :
76
- if self .forced_decisions :
77
- user_context .forced_decisions = copy .deepcopy (self .forced_decisions )
76
+ if self .forced_decisions_map :
77
+ user_context .forced_decisions_map = copy .deepcopy (self .forced_decisions_map )
78
78
79
79
return user_context
80
80
@@ -159,12 +159,12 @@ def set_forced_decision(self, decision_context, decision):
159
159
Returns:
160
160
True if the forced decision has been set successfully.
161
161
"""
162
- if not self .client .config_manager .get_config ():
162
+ if not self .client or not self . client .config_manager .get_config ():
163
163
self .log .logger .error (OptimizelyDecisionMessage .SDK_NOT_READY )
164
164
return False
165
165
166
166
with self .lock :
167
- self .forced_decisions [decision_context ] = decision
167
+ self .forced_decisions_map [decision_context ] = decision
168
168
169
169
return True
170
170
@@ -178,7 +178,7 @@ def get_forced_decision(self, decision_context):
178
178
Returns:
179
179
A forced_decision or None if forced decisions are not set for the parameters.
180
180
"""
181
- if not self .client .config_manager .get_config ():
181
+ if not self .client or not self . client .config_manager .get_config ():
182
182
self .log .logger .error (OptimizelyDecisionMessage .SDK_NOT_READY )
183
183
return None
184
184
@@ -196,13 +196,13 @@ def remove_forced_decision(self, decision_context):
196
196
Returns:
197
197
Returns: true if the forced decision has been removed successfully.
198
198
"""
199
- if not self .client .config_manager .get_config ():
199
+ if not self .client or not self . client .config_manager .get_config ():
200
200
self .log .logger .error (OptimizelyDecisionMessage .SDK_NOT_READY )
201
201
return False
202
202
203
203
with self .lock :
204
- if decision_context in self .forced_decisions :
205
- del self .forced_decisions [decision_context ]
204
+ if decision_context in self .forced_decisions_map :
205
+ del self .forced_decisions_map [decision_context ]
206
206
return True
207
207
208
208
return False
@@ -219,41 +219,41 @@ def remove_all_forced_decisions(self):
219
219
return False
220
220
221
221
with self .lock :
222
- self .forced_decisions .clear ()
222
+ self .forced_decisions_map .clear ()
223
223
224
224
return True
225
225
226
226
def find_forced_decision (self , decision_context ):
227
227
228
228
with self .lock :
229
- if not self .forced_decisions :
229
+ if not self .forced_decisions_map :
230
230
return None
231
231
232
232
# must allow None to be returned for the Flags only case
233
- return self .forced_decisions .get (decision_context )
233
+ return self .forced_decisions_map .get (decision_context )
234
234
235
235
def find_validated_forced_decision (self , decision_context , options ):
236
236
237
237
reasons = []
238
238
239
- forced_decision_response = self .find_forced_decision (decision_context )
239
+ forced_decision = self .find_forced_decision (decision_context )
240
240
241
241
flag_key = decision_context .flag_key
242
242
rule_key = decision_context .rule_key
243
243
244
- if forced_decision_response :
245
- variation = self .client .get_flag_variation_by_key (flag_key , forced_decision_response .variation_key )
244
+ if forced_decision :
245
+ variation = self .client .get_flag_variation_by_key (flag_key , forced_decision .variation_key )
246
246
if variation :
247
247
if rule_key :
248
248
user_has_forced_decision = enums .ForcedDecisionLogs \
249
- .USER_HAS_FORCED_DECISION_WITH_RULE_SPECIFIED .format (forced_decision_response .variation_key ,
249
+ .USER_HAS_FORCED_DECISION_WITH_RULE_SPECIFIED .format (forced_decision .variation_key ,
250
250
flag_key ,
251
251
rule_key ,
252
252
self .user_id )
253
253
254
254
else :
255
255
user_has_forced_decision = enums .ForcedDecisionLogs \
256
- .USER_HAS_FORCED_DECISION_WITHOUT_RULE_SPECIFIED .format (forced_decision_response .variation_key ,
256
+ .USER_HAS_FORCED_DECISION_WITHOUT_RULE_SPECIFIED .format (forced_decision .variation_key ,
257
257
flag_key ,
258
258
self .user_id )
259
259
0 commit comments