-
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
Conversation
optimizely/decision_service.py
Outdated
@@ -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): |
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
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Gets forced decisions based on flag key, rule key and variation. | |
Validates and returns forced decision based on flag key, rule key and variation. |
flag_key = decision_context.flag_key | ||
rule_key = decision_context.rule_key |
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 put these lines inside the if block?
optimizely/decision_service.py
Outdated
# 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 comment
The reason will be displayed to describe this comment to others. Learn more.
please make it more readable.
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 comment
The 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
user_context.logger.info(user_has_forced_decision) | ||
|
||
return variation, 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.
reasons.append(user_has_forced_decision) | ||
user_context.logger.info(user_has_forced_decision) |
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.
i see the same code at 548-549, can we have it only once?
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.
lgtm
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.
A couple of changes suggested
optimizely/decision_service.py
Outdated
""" | ||
reasons = [] | ||
|
||
forced_decision = user_context.find_forced_decision(decision_context) |
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.
Since we remove extra checking from get_forced_decision
, we do not need find_forced_decision
. It's identical to get_forced_decision
. We can remove it and use get_forced_decision
here.
optimizely/decision_service.py
Outdated
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 | ||
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 comment
The 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).
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.
LGTM
3 approvers already approved and yasir's changes are made.
Summary
find_validated_forced_decision
moved to decision service.Test plan