Skip to content
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

Merged
merged 3 commits into from
Jan 6, 2022

Conversation

ozayr-zaviar
Copy link
Contributor

Summary

  • find_validated_forced_decision moved to decision service.

Test plan

  • All unit tests and FSC should pass.

@ozayr-zaviar ozayr-zaviar changed the title refactor: move validate forced decision to decision service refactor: moved validated forced decision to decision service Dec 22, 2021
@@ -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):
Copy link
Contributor

@yasirfolio3 yasirfolio3 Dec 29, 2021

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Gets forced decisions based on flag key, rule key and variation.
Validates and returns forced decision based on flag key, rule key and variation.

Comment on lines +508 to +509
flag_key = decision_context.flag_key
rule_key = decision_context.rule_key
Copy link
Contributor

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?

Comment on lines 512 to 513
# 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
Copy link
Contributor

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 \
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines +532 to +533
reasons.append(user_has_forced_decision)
user_context.logger.info(user_has_forced_decision)
Copy link
Contributor

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?

@msohailhussain msohailhussain marked this pull request as ready for review January 5, 2022 23:51
@msohailhussain msohailhussain requested a review from a team as a code owner January 5, 2022 23:51
@msohailhussain msohailhussain requested a review from jaeopt January 5, 2022 23:51
Copy link
Contributor

@msohailhussain msohailhussain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@jaeopt jaeopt left a 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

"""
reasons = []

forced_decision = user_context.find_forced_decision(decision_context)
Copy link
Contributor

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.

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
Copy link
Contributor

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).

Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@msohailhussain msohailhussain dismissed yasirfolio3’s stale review January 6, 2022 19:52

3 approvers already approved and yasir's changes are made.

@msohailhussain msohailhussain merged commit d1de5b5 into master Jan 6, 2022
@msohailhussain msohailhussain deleted the uzair/move-validate-forced-decision branch January 6, 2022 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants