-
Notifications
You must be signed in to change notification settings - Fork 27
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -298,8 +298,17 @@ 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) | ||||||||||||||
| # Gets variation using variation key or id and flag key. | ||||||||||||||
| # | ||||||||||||||
| # @param flag_key - flag key from which the variation is required. | ||||||||||||||
| # @param target_value - variation value either id or key that will be matched. | ||||||||||||||
| # @param attribute - string representing variation attribute. | ||||||||||||||
| # | ||||||||||||||
| # @return [variation] | ||||||||||||||
| # @return [nil] if no variation found in flag_variation_map. | ||||||||||||||
|
|
||||||||||||||
| def get_flag_variation(flag_key, target_value, attribute) | ||||||||||||||
| project_config.get_variation_from_flag(flag_key, target_value, attribute) | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| # Buckets visitor and sends impression event to Optimizely. | ||||||||||||||
|
|
@@ -1098,12 +1107,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 | ||||||||||||||
| experiment_id != '' ? config.get_variation_id_from_key_by_experiment_id(experiment_id, variation_key) : '' | ||||||||||||||
| else | ||||||||||||||
| variation ? variation['id'] : '' | ||||||||||||||
| end | ||||||||||||||
|
||||||||||||||
| variation_id = if !variation | |
| experiment_id != '' ? config.get_variation_id_from_key_by_experiment_id(experiment_id, variation_key) : '' | |
| else | |
| variation ? variation['id'] : '' | |
| end | |
| variation_id = variation ? variation['id'] : '' |
If it's null from get_flag_variagtion(), then get_variation_id_from_key_by_experiment_id() will also return null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is independent of flag_key, for a/b experiments this will return non-null and get_flag_variation will return null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@msohailhussain A good point! I still see this code can be refactored. Can consider the same comment for this:
https://github.com/optimizely/php-sdk/pull/237/files#r770133288
There was a problem hiding this comment.
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.