Skip to content

Commit a129854

Browse files
Revert "update: modify get_variation to return VariationResult and adjust related logic for improved variation handling"
This reverts commit b901c5f.
1 parent b9a8555 commit a129854

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

optimizely/optimizely.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from .decision.optimizely_decide_option import OptimizelyDecideOption
3030
from .decision.optimizely_decision import OptimizelyDecision
3131
from .decision.optimizely_decision_message import OptimizelyDecisionMessage
32-
from .decision_service import Decision, VariationResult
32+
from .decision_service import Decision
3333
from .error_handler import NoOpErrorHandler, BaseErrorHandler
3434
from .event import event_factory, user_event_factory
3535
from .event.event_processor import BatchEventProcessor, BaseEventProcessor
@@ -535,10 +535,8 @@ def activate(self, experiment_key: str, user_id: str, attributes: Optional[UserA
535535
self.logger.error(enums.Errors.INVALID_PROJECT_CONFIG.format('activate'))
536536
return None
537537

538-
variation_result = self.get_variation(experiment_key, user_id, attributes)
539-
variation_key = None
540-
if variation_result:
541-
variation_key = variation_result['variation'].key
538+
variation_key = self.get_variation(experiment_key, user_id, attributes)
539+
542540
if not variation_key:
543541
self.logger.info(f'Not activating user "{user_id}".')
544542
return None
@@ -614,18 +612,17 @@ def track(
614612

615613
def get_variation(
616614
self, experiment_key: str, user_id: str, attributes: Optional[UserAttributes] = None
617-
) -> Optional[VariationResult]:
618-
"""
619-
Returns the variation result for the given user in the specified experiment.
615+
) -> Optional[str]:
616+
""" Gets variation where user will be bucketed.
620617
621618
Args:
622-
experiment_key: The key identifying the experiment.
623-
user_id: The user ID.
624-
attributes: Optional dictionary of user attributes.
619+
experiment_key: Experiment for which user variation needs to be determined.
620+
user_id: ID for user.
621+
attributes: Dict representing user attributes.
625622
626623
Returns:
627-
A VariationResult object containing the variation assigned to the user, or None if the user is not
628-
bucketed into any variation or the experiment is not running.
624+
Variation key representing the variation the user will be bucketed in.
625+
None if user is not in experiment or if experiment is not Running.
629626
"""
630627

631628
if not self.is_valid:
@@ -678,7 +675,7 @@ def get_variation(
678675
{'experiment_key': experiment_key, 'variation_key': variation_key},
679676
)
680677

681-
return variation_result
678+
return variation_key
682679

683680
def is_feature_enabled(self, feature_key: str, user_id: str, attributes: Optional[UserAttributes] = None) -> bool:
684681
""" Returns true if the feature is enabled for the given user.

0 commit comments

Comments
 (0)