diff --git a/lib/ldclient-rb/ldclient.rb b/lib/ldclient-rb/ldclient.rb index 37d80e9a..d96dd1f7 100644 --- a/lib/ldclient-rb/ldclient.rb +++ b/lib/ldclient-rb/ldclient.rb @@ -407,6 +407,12 @@ def evaluate_internal(key, user, default, event_factory) return detail end + if user[:key].nil? + @config.logger.warn { "[LDClient] Variation called with nil user key; returning default value" } + detail = Evaluator.error_result(EvaluationReason::ERROR_USER_NOT_SPECIFIED, default) + return detail + end + if !initialized? if @store.initialized? @config.logger.warn { "[LDClient] Client has not finished initializing; using last known values from feature store" } diff --git a/spec/ldclient_spec.rb b/spec/ldclient_spec.rb index cad4c03c..8e2ef650 100644 --- a/spec/ldclient_spec.rb +++ b/spec/ldclient_spec.rb @@ -171,20 +171,12 @@ def event_processor client.variation("key", user_anonymous, "default") end - it "queues a feature event for an existing feature when user key is nil" do + it "does not queue a feature event for an existing feature when user key is nil" do config.feature_store.init({ LaunchDarkly::FEATURES => {} }) config.feature_store.upsert(LaunchDarkly::FEATURES, feature_with_value) bad_user = { name: "Bob" } - expect(event_processor).to receive(:add_event).with(hash_including( - kind: "feature", - key: "key", - version: 100, - user: bad_user, - value: "default", - default: "default", - trackEvents: true, - debugEventsUntilDate: 1000 - )) + expect(event_processor).not_to receive(:add_event) + expect(logger).to receive(:warn) client.variation("key", bad_user, "default") end