-
Notifications
You must be signed in to change notification settings - Fork 36
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
refactor: moved validated forced decision to decision service #369
Changes from 1 commit
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 | ||||
---|---|---|---|---|---|---|
|
@@ -378,8 +378,8 @@ def get_variation_for_rollout(self, project_config, feature, user): | |||||
# check forced decision first | ||||||
rule = rollout_rules[index] | ||||||
optimizely_decision_context = OptimizelyUserContext.OptimizelyDecisionContext(feature.key, rule.key) | ||||||
forced_decision_variation, reasons_received = user.find_validated_forced_decision( | ||||||
optimizely_decision_context) | ||||||
forced_decision_variation, reasons_received = self.validated_forced_decision( | ||||||
optimizely_decision_context, user) | ||||||
decide_reasons += reasons_received | ||||||
|
||||||
if forced_decision_variation: | ||||||
|
@@ -464,8 +464,8 @@ def get_variation_for_feature(self, project_config, feature, user_context, optio | |||||
optimizely_decision_context = OptimizelyUserContext.OptimizelyDecisionContext(feature.key, | ||||||
experiment.key) | ||||||
|
||||||
forced_decision_variation, reasons_received = user_context.find_validated_forced_decision( | ||||||
optimizely_decision_context) | ||||||
forced_decision_variation, reasons_received = self.validated_forced_decision( | ||||||
optimizely_decision_context, user_context) | ||||||
decide_reasons += reasons_received | ||||||
|
||||||
if forced_decision_variation: | ||||||
|
@@ -489,3 +489,63 @@ def get_variation_for_feature(self, project_config, feature, user_context, optio | |||||
if rollout_variation_reasons: | ||||||
decide_reasons += rollout_variation_reasons | ||||||
return variation, decide_reasons | ||||||
|
||||||
def validated_forced_decision(self, decision_context, user_context): | ||||||
""" | ||||||
Gets forced decisions based on flag key, rule key and variation. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Args: | ||||||
decision context: a decision context | ||||||
user_context context: a user context | ||||||
|
||||||
Returns: | ||||||
Variation of the forced decision. | ||||||
""" | ||||||
reasons = [] | ||||||
|
||||||
forced_decision = user_context.find_forced_decision(decision_context) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we remove extra checking from |
||||||
|
||||||
flag_key = decision_context.flag_key | ||||||
rule_key = decision_context.rule_key | ||||||
Comment on lines
+509
to
+510
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we put these lines inside the if block? |
||||||
|
||||||
if forced_decision: | ||||||
# we use config here so we can use get_flag_variation() function which is defined in project_config | ||||||
# otherwise we would us user_context.client instead of config | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please make it more readable. |
||||||
config = user_context.client.config_manager.get_config() if user_context.client else None | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass config as a parameter from caller (not from user_context to break a cycle). |
||||||
if not config: | ||||||
return None, reasons | ||||||
variation = config.get_flag_variation(flag_key, 'key', forced_decision.variation_key) | ||||||
if variation: | ||||||
if rule_key: | ||||||
user_has_forced_decision = enums.ForcedDecisionLogs \ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please update this name to something that suggests it is a reason. |
||||||
.USER_HAS_FORCED_DECISION_WITH_RULE_SPECIFIED.format(forced_decision.variation_key, | ||||||
flag_key, | ||||||
rule_key, | ||||||
user_context.user_id) | ||||||
|
||||||
else: | ||||||
user_has_forced_decision = enums.ForcedDecisionLogs \ | ||||||
.USER_HAS_FORCED_DECISION_WITHOUT_RULE_SPECIFIED.format(forced_decision.variation_key, | ||||||
flag_key, | ||||||
user_context.user_id) | ||||||
|
||||||
reasons.append(user_has_forced_decision) | ||||||
user_context.logger.info(user_has_forced_decision) | ||||||
Comment on lines
+530
to
+531
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i see the same code at 548-549, can we have it only once? |
||||||
|
||||||
return variation, reasons | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
else: | ||||||
if rule_key: | ||||||
user_has_forced_decision_but_invalid = enums.ForcedDecisionLogs \ | ||||||
.USER_HAS_FORCED_DECISION_WITH_RULE_SPECIFIED_BUT_INVALID.format(flag_key, | ||||||
rule_key, | ||||||
user_context.user_id) | ||||||
else: | ||||||
user_has_forced_decision_but_invalid = enums.ForcedDecisionLogs \ | ||||||
.USER_HAS_FORCED_DECISION_WITHOUT_RULE_SPECIFIED_BUT_INVALID.format(flag_key, | ||||||
user_context.user_id) | ||||||
|
||||||
reasons.append(user_has_forced_decision_but_invalid) | ||||||
user_context.logger.info(user_has_forced_decision_but_invalid) | ||||||
|
||||||
return None, reasons |
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.
can we rename it to something that's more readable and clear? the previous one seemed okay
find_validated_forced_decision