@@ -180,14 +180,14 @@ def _send_event(self, event):
180180
181181 def track (self , event_name , user , data = None ):
182182 self ._sanitize_user (user )
183- if user .get ('key' , "" ) == "" :
184- log .warn ("Missing or empty User key when calling track()." )
183+ if user is None or user .get ('key' ) is None :
184+ log .warn ("Missing user or user key when calling track()." )
185185 self ._send_event ({'kind' : 'custom' , 'key' : event_name , 'user' : user , 'data' : data })
186186
187187 def identify (self , user ):
188188 self ._sanitize_user (user )
189- if user .get ('key' , "" ) == "" :
190- log .warn ("Missing or empty User key when calling identify()." )
189+ if user is None or user .get ('key' ) is None :
190+ log .warn ("Missing user or user key when calling identify()." )
191191 self ._send_event ({'kind' : 'identify' , 'key' : user .get ('key' ), 'user' : user })
192192
193193 def is_offline (self ):
@@ -222,11 +222,14 @@ def send_event(value, version=None):
222222 send_event (default )
223223 return default
224224
225- if user .get ('key' , "" ) == "" :
226- log .warn ("Missing or empty User key when evaluating Feature Flag key: " + key + ". Returning default." )
225+ if user is None or user .get ('key' ) is None :
226+ log .warn ("Missing user or user key when evaluating Feature Flag key: " + key + ". Returning default." )
227227 send_event (default )
228228 return default
229229
230+ if user .get ('key' , "" ) == "" :
231+ log .warn ("User key is blank. Flag evaluation will proceed, but the user will not be stored in LaunchDarkly." )
232+
230233 flag = self ._store .get (key )
231234 if not flag :
232235 log .warn ("Feature Flag key: " + key + " not found in Feature Store. Returning default." )
@@ -254,14 +257,14 @@ def all_flags(self, user):
254257 log .warn ("all_flags() called before client has finished initializing! Returning None" )
255258 return None
256259
257- if user .get ('key' , "" ) == "" :
258- log .warn ("Missing or empty User key when calling all_flags(). Returning None." )
260+ if user is None or user .get ('key' ) is None :
261+ log .warn ("User or user key is None when calling all_flags(). Returning None." )
259262 return None
260263
261264 return {k : evaluate (v , user , self ._store )[0 ] for k , v in self ._store .all ().items () or {}}
262265
263266 def secure_mode_hash (self , user ):
264- if user .get ('key' , "" ) == "" :
267+ if user .get ('key' ) is None :
265268 return ""
266269 return hmac .new (self ._sdk_key .encode (), user .get ('key' ).encode (), hashlib .sha256 ).hexdigest ()
267270
0 commit comments