-
Notifications
You must be signed in to change notification settings - Fork 22
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
fix: avoid creating merge fields if we can't get merge fields #1729
base: release
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release #1729 +/- ##
=============================================
+ Coverage 23.07% 23.27% +0.20%
+ Complexity 2713 2709 -4
=============================================
Files 49 49
Lines 10761 10748 -13
=============================================
+ Hits 2483 2502 +19
+ Misses 8278 8246 -32 ☔ View full report in Codecov by Sentry. |
Good catch! That's why this error was never being logged! I couldn't get it all to work, here are a few things I saw:
|
@leogermani I think 345229b should stop the sync by throwing an exception if we encounter a merge fields error. Note that since we're using the |
This might be the case if you still have the temp error being triggered by the |
Right, it's expected to fail, but also to schedule a new retry until it reaches 5 attempts. It didn't schedule the second retry |
) | ||
); | ||
} | ||
$result = $this->validate( $mc->put( "lists/$list_id/members/$member_hash", $update_payload ) ); |
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.
@leogermani I think this change is still safe because it should result in the same behavior and error code—the removed code was mainly duplicating some of the checks in the validate()
method. Happy to revert this too if you prefer.
This reverts commit 363b725.
@leogermani I've scaled back the changes in this PR to include only the additional validation and error logging, so this should be ready for another review. |
All Submissions:
Changes proposed in this Pull Request:
When preparing a contact's data sync, we compare the contact's meta fields with the existing merge fields in the audience so that we can use the fields that exist and create the ones that don't yet exist. However, if we can't get info about the existing merge fields via the Mailchimp API for any reason, we should stop the sync to avoid potentially creating duplicate merge fields.
This PR also uses the
validate
method to catch any potential error-like responses from the Mailchimp API.Coupled with Automattic/newspack-plugin#3639, this PR will also schedule a retry sync after five minutes if we fail to fetch merge fields, up to a maximum of five times.
Addresses:
1200550061930446-as-1208959720314117
How to test the changes in this Pull Request:
NOTE: leaving the below in place for the record, but it's no longer part of this PR.
Click to see additional testing steps (no longer part of this PR)
$response = [];
here to simulate a non-error response from the Mailchimp API that nonetheless fails to return merge field data.wp cron event list
and confirm there's a non-recurringnewspack_scheduled_esp_sync
job scheduled for 5 minutes in the future.wp cron event run newspack_scheduled_esp_sync
to trigger the job immediately. Repeat this 5 times.Failed to sync contact <email address> after 5 retries
is logged, and that there's no morenewspack_scheduled_esp_sync
job scheduled.Newspack\Reader_Activation\Sync::schedule_sync( $user_id, 'Testing scheduled sync', 30 );
and confirm that the scheduled sync happens successfully after 30 seconds.Other information: