forked from mozmeao/basket
-
Notifications
You must be signed in to change notification settings - Fork 2
No migration #37
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
Draft
jacobpenny
wants to merge
13
commits into
silverorange:main
Choose a base branch
from
jacobpenny:no-migration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
No migration #37
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8cb3641
Make newly generated email_ids and basket_tokens the same
jacobpenny e0de07d
Send email_id / external_id as token in recovery emails
jacobpenny e09839c
Don't pass email_id to send_confirm_message
jacobpenny b7074e0
Use token to look up user by email_id in CTMS
jacobpenny ef07105
Update Braze class to treat email_id as token
jacobpenny 8856393
Remove token param from send_recovery_message
jacobpenny d29488f
Delay execution of some fxa events
jacobpenny f3425d0
Remove user_attributes_v1.basket_token entirely
jacobpenny 196985b
Rename send_recovery_message param from email_id to token
jacobpenny 6ac3328
Remove unnecessary test
jacobpenny 8359740
Remove email_id param from braze.get
jacobpenny d30c66d
Formatting
jacobpenny ba1581c
Keep track of legacy ctms token for auth purposes
jacobpenny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,20 +23,8 @@ | |
| BRAZE_OPTIMAL_DELAY = timedelta(minutes=5) | ||
|
|
||
|
|
||
| # These tasks cannot be placed in basket/news/tasks.py because it would | ||
| # This task cannot be placed in basket/news/tasks.py because it would | ||
| # create a circular dependency. | ||
| @rq_task | ||
| def migrate_external_id_task(current_external_id, new_external_id): | ||
| braze.interface.migrate_external_id( | ||
| [ | ||
| { | ||
| "current_external_id": current_external_id, | ||
| "new_external_id": new_external_id, | ||
| } | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| @rq_task | ||
| def add_fxa_id_alias_task(external_id, fxa_id): | ||
| braze.interface.add_fxa_id_alias(external_id, fxa_id) | ||
|
|
@@ -366,7 +354,6 @@ def __init__(self, interface): | |
|
|
||
| def get( | ||
| self, | ||
| email_id=None, | ||
| token=None, | ||
| email=None, | ||
| fxa_id=None, | ||
|
|
@@ -381,18 +368,6 @@ def get( | |
| @return: dict, or None if not found | ||
|
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're not using the email_id param in braze.get, we should probably get rid of it to avoid even more confusion |
||
| """ | ||
|
|
||
| # If we only have a token or fxa_id and the Braze migrations for them haven't been | ||
| # completed we won't be able to look up the user. We add a temporary shim here which | ||
| # will fetch the email from CTMS. This shim can be disabled/removed after the migrations | ||
| # are complete. | ||
| if not email and settings.BRAZE_CTMS_SHIM_ENABLE: | ||
| try: | ||
| ctms_response = ctms.get(token=token, fxa_id=fxa_id) | ||
| if ctms_response: | ||
| email = ctms_response.get("email") | ||
| except Exception: | ||
| log.warn("Unable to fetch email from CTMS in braze.get shim") | ||
|
|
||
| user_response = self.interface.export_users( | ||
| email, | ||
| [ | ||
|
|
@@ -424,6 +399,20 @@ def get( | |
|
|
||
| return self.from_vendor(user_data, subscriptions) | ||
|
|
||
| # If we only have an outdated token or the Braze fxa_id migrations haven't been | ||
| # completed we won't be able to look up the user. We add a temporary shim here which | ||
| # will fetch the email from CTMS. This shim can be disabled/removed after the migration | ||
| # is complete. | ||
| elif not email and (fxa_id or token) and settings.BRAZE_CTMS_SHIM_ENABLE: | ||
| try: | ||
| ctms_response = ctms.get(token=token, fxa_id=fxa_id) | ||
| if ctms_response: | ||
| ctms_email = ctms_response.get("email") | ||
| if ctms_email: | ||
| return self.get(email=ctms_email) | ||
| except Exception: | ||
| log.warn("Unable to fetch email from CTMS in braze.get shim") | ||
|
|
||
| def add(self, data): | ||
| """ | ||
| Create a user record. | ||
|
|
@@ -441,14 +430,6 @@ def add(self, data): | |
| enqueue_in=BRAZE_OPTIMAL_DELAY, | ||
| ) | ||
|
|
||
| token = data.get("token") | ||
| if token and settings.BRAZE_PARALLEL_WRITE_ENABLE: | ||
| migrate_external_id_task.delay( | ||
| external_id, | ||
| token, | ||
| enqueue_in=BRAZE_OPTIMAL_DELAY, | ||
| ) | ||
|
|
||
| return {"email": {"email_id": external_id}} | ||
|
|
||
| def update(self, existing_data, update_data): | ||
|
|
@@ -539,7 +520,8 @@ def from_vendor(self, braze_user_data, subscription_groups): | |
| "last_modified_date": user_attributes.get("updated_at"), | ||
| "optin": braze_user_data.get("email_subscribe") == "opted_in", | ||
| "optout": braze_user_data.get("email_subscribe") == "unsubscribed", | ||
| "token": user_attributes.get("basket_token"), | ||
| "token": braze_user_data["external_id"], | ||
| "ctms_legacy_token": user_attributes.get("basket_token"), | ||
| "fxa_service": user_attributes.get("fxa_first_service"), | ||
| "fxa_lang": user_attributes.get("fxa_lang"), | ||
| "fxa_primary_email": user_attributes.get("fxa_primary_email"), | ||
|
|
@@ -563,9 +545,7 @@ def to_vendor(self, basket_user_data=None, update_data=None, events=None): | |
| country = process_country(updated_user_data.get("country") or None) | ||
| language = process_lang(updated_user_data.get("lang") or None) | ||
|
|
||
| external_id = ( | ||
| updated_user_data.get("token") if not existing_user_data and settings.BRAZE_ONLY_WRITE_ENABLE else updated_user_data.get("email_id") | ||
| ) | ||
| external_id = updated_user_data.get("email_id") | ||
|
|
||
| if not external_id: | ||
| raise ValueError("Missing Braze external_id") | ||
|
|
@@ -593,7 +573,7 @@ def to_vendor(self, basket_user_data=None, update_data=None, events=None): | |
| "subscription_groups": subscription_groups, | ||
| "user_attributes_v1": [ | ||
| { | ||
| "basket_token": updated_user_data.get("token"), | ||
| "basket_token": updated_user_data.get("ctms_legacy_token") or updated_user_data.get("token"), | ||
| "created_at": {"$time": updated_user_data.get("created_date", now)}, | ||
| "email_lang": language, | ||
| "mailing_country": country, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Did you mean to leave this comment here?
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.
Yes because there is still one task (the alias one)
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.
Maybe it's worth removing the empty space between that comment and that task then? So it's clear that's what it's about
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.
oh yes, indeed