Skip to content

feat: clone user context #312

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

Closed
wants to merge 4 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions optimizely/user_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def __init__(self, optimizely_client, user_id, user_attributes=None):

self.logger = _logging.reset_logger(self.logger_name)

def clone(self):
return UserContext(self.client, self.user_id, self.user_attributes)

def set_attribute(self, attribute_key, attribute_value):
"""
sets a attribute by key for this user context.
Expand All @@ -66,7 +69,7 @@ def decide(self, key, options=None):
self.logger.error("Optimizely Client invalid")
return None

return self.client.decide(self, key, options)
return self.client.decide(self.clone(), key, options)

def decide_for_keys(self, keys, options=None):
"""
Expand All @@ -82,7 +85,7 @@ def decide_for_keys(self, keys, options=None):
self.logger.error("Optimizely Client invalid")
return None

self.client.decide_for_keys(self, keys, options)
self.client.decide_for_keys(self.clone(), keys, options)

def decide_all(self, options=None):
"""
Expand All @@ -97,7 +100,7 @@ def decide_all(self, options=None):
self.logger.error("Optimizely Client invalid")
return None

self.client.decide_all(self, options)
self.client.decide_all(self.clone(), options)

def track_event(self, event_key, event_tags=None):
self.client.track(event_key, self.user_id, self.user_attributes, event_tags)