Skip to content

Add forced-decisions APIs to OptimizelyUserContext - #361

Merged
Matjaz Pirnovar (Mat001) merged 42 commits into
masterfrom
mpirnovar/forced_decisions
Dec 6, 2021
Merged

Matjaz Pirnovar (Mat001) merged 42 commits into
masterfrom
mpirnovar/forced_decisions

Conversation

@Mat001

@Mat001 Matjaz Pirnovar (Mat001) commented Oct 1, 2021 •

Copy link
Copy Markdown
Contributor

Summary

Add a set of new APIs for forced-decisions to OptimizelyUserContext:

  • set_forced_decision
  • get_forced_decision
  • remove_forced_decision
  • remove_all_forced_decisions

Test plan

Issues

@jaeopt Jae Kim (jaeopt) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some early comments :)

Comment thread optimizely/optimizely_user_context.py Resolved
Comment thread optimizely/optimizely_user_context.py Resolved
Comment thread optimizely/optimizely_user_context.py Resolved
Comment thread optimizely/optimizely_user_context.py Resolved
Comment thread optimizely/optimizely_user_context.py Resolved
Comment thread optimizely/optimizely.py Resolved
Comment thread optimizely/helpers/enums.py Resolved
@coveralls

Coveralls (coveralls) commented Oct 20, 2021 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.3%) to 95.829% when pulling 201548f on mpirnovar/forced_decisions into a1e31eb on master.

Co-authored-by: ozayr-zaviar <54209343+ozayr-zaviar@users.noreply.github.com>
Co-authored-by: ozayr-zaviar <54209343+ozayr-zaviar@users.noreply.github.com>
Co-authored-by: ozayr-zaviar <54209343+ozayr-zaviar@users.noreply.github.com>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

rest of the comments, Muhammad Noman (@mnoman09) will verify.

Comment thread optimizely/decision_service.py Resolved
Comment thread optimizely/decision_service.py Resolved
Comment thread optimizely/decision_service.py Resolved
Comment thread optimizely/event/user_event_factory.py Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

few more comments.

Comment thread optimizely/decision_service.py Resolved
Comment thread optimizely/entities.py Resolved
Comment thread optimizely/optimizely.py Resolved
Comment thread optimizely/optimizely_user_context.py Resolved
Comment thread optimizely/optimizely_user_context.py Resolved
Comment thread optimizely/optimizely_user_context.py Resolved
Comment thread optimizely/project_config.py Resolved
Comment thread optimizely/project_config.py Resolved
Comment thread optimizely/project_config.py Resolved
Comment thread optimizely/project_config.py Resolved

@mnoman09 Muhammad Noman (mnoman09) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested some changes.

Comment thread optimizely/decision_service.py Resolved
Comment thread optimizely/decision_service.py Resolved
Comment thread optimizely/optimizely_user_context.py Resolved
Comment thread optimizely/decision_service.py Resolved
Comment thread tests/test_config.py Resolved
Comment thread optimizely/decision_service.py Resolved
@Mat001

Copy link
Copy Markdown
Contributor Author

Mirza Sohail Hussain (@msohailhussain) Muhammad Noman (@mnoman09) I consolidated the functions into one. Here:

def get_flag_variation(self, flag_key, variation_attribute, target_value):
"""
Gets variation by specified variation attribute.
For example if variation_attribute is id, the function gets variation by using variation_id.
If object_attribute is key, the function gets variation by using variation_key.
We used to have two separate functions:
get_flag_variation_by_id()
get_flag_variation_by_key()
This function consolidates both functions into one.
Important to always relate object_attribute to the target value.
Should never enter for example object_attribute=key and target_value=variation_id.
Correct is object_attribute=key and target_value=variation_key.
Args:
flag_key: flag key
variation_attribute: id or key for example. The part after the dot notation (id in variation.id)
target_value: target value we want to get for example variation_id or variation_key
Returns:
Variation as a map.
"""
if not flag_key:
return None
variations = self.flag_variations_map.get(flag_key)
for variation in variations:
if getattr(variation, variation_attribute) == target_value:
return variation
return None

When you review this pls look carefully. The two functions I consolidated were each called on a different object:

get_flag_variation_by_id() was called on project_config. ----> in user_event_factory.py
get_flag_variation_by_key() was called on self.client. --------> inside find_validated_forced_decision()

So I made a little change in find_validated_forced_decision() here, so the single function is only called on project_config: https://github.com/optimizely/python-sdk/pull/361/files#diff-4df94492754236d1784d8b2987b84acd6af0ea3d97a0a2e54e61fb3f03acb04cR265-R268

unit tests and FSC tests pass.

@jaeopt Jae Kim (jaeopt) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few changes suggested

Comment thread optimizely/decision_service.py Resolved
Comment thread optimizely/decision_service.py Resolved
Comment thread optimizely/optimizely_user_context.py Resolved
Comment thread optimizely/project_config.py Resolved
* project config refactor

* use existing loop to generate flag_variation_map

* get_variation_from_experiment_rule and get_variation_from_delivery_rule removed

* fsc test fix

* comment addressed

* commented code removed

* comments from main forced decision PR resolved

Co-authored-by: ozayr-zaviar <uzairzaviar@gmail.com>

@jaeopt Jae Kim (jaeopt) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All look good except for a small change suggested!

Comment thread optimizely/optimizely_user_context.py Resolved

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM!

@Mat001

Copy link
Copy Markdown
Contributor Author

Mirza Sohail Hussain (@msohailhussain) Muhammad Noman (@mnoman09) Yasir Folio3 (@yasirfolio3) Can you please approve this PR so I can merge it? (mark requested changes as resolved) TY

@jaeopt Jae Kim (jaeopt) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@msohailhussain
Mirza Sohail Hussain (msohailhussain) dismissed stale reviews from Muhammad Noman (mnoman09) and Yasir Folio3 (yasirfolio3) December 6, 2021 18:38

already approved by 2 devx members.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm on behalf of yasir and noman.

@Mat001
Matjaz Pirnovar (Mat001) merged commit d85d272 into master Dec 6, 2021
@Mat001
Matjaz Pirnovar (Mat001) deleted the mpirnovar/forced_decisions branch December 6, 2021 18:46
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.

8 participants