8000 fix: Forced variation not available in experiment by ozayr-zaviar · Pull Request #292 · optimizely/ruby-sdk · GitHub
[go: up one dir, main page]

Skip to content

fix: Forced variation not available in experiment #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
J 8000 ump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fixes
  • Loading branch information
ozayr-zaviar committed Dec 14, 2021
commit ee5c0d7a3672b94f3d94fc1d83d604499b101f91
21 changes: 11 additions & 10 deletions lib/optimizely.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ def decide(user_context, key, decide_options = [])
experiment = decision.experiment
rule_key = experiment ? experiment['key'] : nil
variation = decision['variation']
variation_key = variation['key']
feature_enabled = variation['featureEnabled']
variation_key = variation ? variation['key'] : nil
feature_enabled = variation ? variation['featureEnabled'] : false
decision_source = decision.source
end

8000 Expand Down Expand Up @@ -298,8 +298,8 @@ def decide_for_keys(user_context, keys, decide_options = [])
decisions
end

def get_flag_variation_by_key(flag_key, variation_key)
project_config.get_variation_from_flag(flag_key, variation_key)
def get_flag_variation(flag_key, target_value, attribute)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add description of this method.

project_config.get_variation_from_flag(flag_key, target_value, attribute)
end

# Buckets visitor and sends impression event to Optimizely.
Expand Down Expand Up @@ -1098,12 +1098,13 @@ def send_impression(config, experiment, variation_key, flag_key, rule_key, enabl
experiment_id = experiment['id']
experiment_key = experiment['key']

if experiment_id != ''
variation_id = config.get_variation_id_from_key_by_experiment_id(experiment_id, variation_key)
else
varaition = get_flag_variation_by_key(flag_key, variation_key)
variation_id = varaition ? varaition['id'] : ''
end
variation = get_flag_variation(flag_key, variation_key, 'key')

variation_id = if !variation
config.get_variation_id_from_key_by_experiment_id(experiment_id, variation_key)
else
variation ? variation['id'] : ''
end

metadata = {
flag_key: flag_key,
Expand Down
4 changes: 2 additions & 2 deletions lib/optimizely/config/datafile_project_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ def get_audience_from_id(audience_id)
nil
end

def get_variation_from_flag(flag_key, variation_key)
def get_variation_from_flag(flag_key, target_value, attribute)
variations = @flag_variation_map[flag_key]
return variations.select { |variation| variation['key'] == variation_key }.first if variations
return variations.select { |variation| variation[attribute] == target_value }.first if variations

nil
end
Expand Down
1 change: 1 addition & 0 deletions lib/optimizely/decision_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def get_variation_for_feature_experiment(project_config, feature_flag, user_cont
next unless variation_id

variation = project_config.get_variation_from_id_by_experiment_id(experiment_id, variation_id)
variation = project_config.get_variation_from_flag(feature_flag['key'], variation_id, 'id') if variation.nil?

return Decision.new(experiment, variation, DECISION_SOURCES['FEATURE_TEST']), decide_reasons
end
Expand Down
2 changes: 1 addition & 1 deletion lib/optimizely/optimizely_user_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def find_validated_forced_decision(context)
reasons = []
target = rule_key ? "flag (#{flag_key}), rule (#{rule_key})" : "flag (#{flag_key})"
if variation_key
variation = @optimizely_client.get_flag_variation_by_key(flag_key, variation_key)
variation = @optimizely_client.get_flag_variation(flag_key, variation_key, 'key')
if variation
reason = "Variation (#{variation_key}) is mapped to #{target} and user (#{@user_id}) in the forced decision map."
reasons.push(reason)
Expand Down
0