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

Skip to content

fix: Forced variation not available in experiment #367

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 8 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
9 changes: 5 additions & 4 deletions optimizely/event/user_event_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ def create_impression_event(
if activated_experiment:
experiment_id = activated_experiment.id

if variation_id and experiment_id:
variation = project_config.get_variation_from_id_by_experiment_id(experiment_id, variation_id)
# need this condition when we send events involving forced decisions
elif variation_id and flag_key:
if variation_id and flag_key:
variation = project_config.get_flag_variation(flag_key, 'id', variation_id)
if not variation and variation_id and experiment_id:
# need this condition when we send events involving forced decisions
variation = project_config.get_variation_from_id_by_experiment_id(experiment_id, variation_id)

event_context = user_event.EventContext(
project_config.account_id, project_config.project_id, project_config.revision, project_config.anonymize_ip,
)
Expand Down
15 changes: 8 additions & 7 deletions optimizely/project_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ def get_variation_from_id_by_experiment_id(self, experiment_id, variation_id):
variation_id in self.variation_id_map_by_experiment_id[experiment_id]):
return self.variation_id_map_by_experiment_id[experiment_id][variation_id]

self.logger.error('Variation with id "%s" not defined in the datafile for experiment "%s".',
variation_id, experiment_id)
self.logger.error('Variation with id "%s" not defined in the datafile for experiment "%s".' %
(variation_id, experiment_id))

return {}

Expand All @@ -628,8 +628,8 @@ def get_variation_from_key_by_experiment_id(self, experiment_id, variation_key):
variation_key in self.variation_key_map_by_experiment_id[experiment_id]):
return self.variation_key_map_by_experiment_id[experiment_id][variation_key]

self.logger.error('Variation with key "%s" not defined in the datafile for experiment "%s".',
variation_key, experiment_id)
self.logger.error('Variation with key "%s" not defined in the datafile for experiment "%s".' %
(variation_key, experiment_id))

return {}

Expand Down Expand Up @@ -661,8 +661,9 @@ def get_flag_variation(self, flag_key, variation_attribute, target_value):
return None

variations = self.flag_variations_map.get(flag_key)
for variation in variations:
if getattr(variation, variation_attribute) == target_value:
return variation
if variations:
for variation in variations:
if getattr(variation, variation_attribute) == target_value:
return variation

return None
0