-
Notifications
You must be signed in to change notification settings - Fork 18
Implement a newsletter template fallback system #2728
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
Conversation
- If the latest newsletter template_id in airtable is unable to be found in our DB, then we will fallback to the most recent template_id that we can find in our DB. Currently this looks back at the last 3 newsletter installments to find a template_id that exists in the db
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.
Pull request overview
This PR implements a fallback mechanism for newsletter template retrieval by iterating through up to 3 most recent template pairs from Airtable when the latest template is not found in the database. If a template exists in the DB, it is used to send newsletters to subscribers; otherwise, the system falls back to older templates with appropriate logging, and raises a 500 error if none of the 3 templates are found.
Key changes:
- Modified Airtable query to fetch 3 most recent newsletter template pairs instead of 1
- Added iterative fallback logic with logging when newer templates are unavailable
- Enhanced error handling to distinguish between template retrieval failures and missing templates
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| app/newsletter/rest.py | Implements core fallback iteration logic through 3 most recent templates with SQLAlchemyError handling and warning logs |
| app/clients/airtable/models.py | Changes Airtable query from fetching 1 to 3 most recent newsletter template records |
| tests/app/newsletter/test_rest.py | Adds test coverage for fallback behavior and all-templates-not-found scenario |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Add check for and create mailing list logic to the `from_email()` method
|
|
||
| # Iterate through the 3 latest newsletter templates from Airtable and use the most recent | ||
| # template that currently exists in the DB | ||
| for index, newsletter_template in enumerate(latest_newsletter_templates): |
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.
Shame on my non-pythonic use of index here.
smcmurtry
left a comment
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.
I'm able to get the DEV tables set up again after deleting them using this code.
It's not passing the test I'm doing when adding bad template ids though:
- add a new row to the bottom of "DEV - current newsletter templates" with bad ids like "abc" etc
- add a 2nd bad row
- click the "send me the latest newsletter" button
- I am redirected to the signup page
Summary | Résumé
This PR implements a fallback mechanism for fetching newsletter templates from the DB.
How it works
template_id-> log a warning that we had to use a fallback, and which subscriber we sent that toCurrent newsletter templatesAirtable and likely requires some level of manual intervention.Additional fix:
We're also implementing a fix to ensure that the
from_email()method checks for the existence of the mailing list table before executing aformula queryagainst it.Related Issues | Cartes liées
Test instructions | Instructions pour tester la modification
With the most recent template pair being bad data
c3b6603a-15cf-4509-a79f-524da9800da1Send me the most recent newsletterbuttonWithout bad data
Testing the
from_email()fixDEV - Mailing ListandDEV - Latest newsletter templatestablesDEV - Latest newsletter templatesis missing theCreated atcolumn so the endpoint is throwing back an error. (see note in release instructions for why this happens)DEV - Latest newsletter templatestable was createdCreated at(case sensitive)ISO formatTrue24 hoursc3a0273c-ea55-4de4-a688-018ab909795d(when doing this in prod use the real newsletter template_ids)d6545dba-6cac-48bb-94ea-95dcd5c621f6Release Instructions | Instructions pour le déploiement
Go through the
Testing the from_email() fixsteps again right after releasing to prod. This will ensure that:PROD - Mailing Listtable gets generatedPROD - Latest newsletter templatestable gets generatedCreated atcolumn is performedUnfortunately Airtable doesn't support creation of the
Created Timefield type via their API. So we have to manually do that ourselves, making this process very much a PITA as we now have to remember this restriction in the event that something happens to the tables in the future.Reviewer checklist | Liste de vérification du réviseur