Skip to content

Conversation

@whabanks
Copy link
Contributor

Summary | Résumé

This PR implements a fallback mechanism for fetching newsletter templates from the DB.

How it works

  1. Get the last 3 pairs of newsletter template_ids from Airtable
  2. Iterate through them, starting at the most recent pair
  3. Check if it exists in the DB -> if it does, we use this template to send the user the latest newsletter
  4. Otherwise, continue iterating backwards through the newsletter instalments until we find one that exists in the DB.
    • When we have to use a past template_id -> log a warning that we had to use a fallback, and which subscriber we sent that to
  5. If the previous 3 template_ids all do not exist in the DB, we raise a 500 error up to admin as this indicates there's something very wrong with the Current newsletter templates Airtable and likely requires some level of manual intervention.

Test instructions | Instructions pour tester la modification

With the most recent template pair being bad data

  1. In Airtable Add a pair of non-existent template_ids to the table, use this for both EN and FR: c3b6603a-15cf-4509-a79f-524da9800da1
  2. Sign up for and confirm your subscription to the newsletter
  3. Click the Send me the most recent newsletter button
  4. Note you receive the newsletter
  5. Note the application logs contain a warning log:
WARNING None "Most recent template from Airtable: c3b6603a-15cf-4509-a79f-524da9800da1 not found in database. Using fallback template: c3a0273c-ea55-4de4-a688-018ab909795d for subscriber: `your_sub_id`

Without bad data

  1. Delete the row you added above
  2. Send yourself the most recent newsletter again
  3. Note you received the newsletter
  4. Note the absence of the warning logging

whabanks and others added 3 commits December 10, 2025 17:02
- 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
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@whabanks whabanks requested a review from jimleroyer as a code owner December 10, 2025 22:07
Copilot AI review requested due to automatic review settings December 10, 2025 22:07
Copy link
Contributor

Copilot AI left a 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 to handle cases where the most recent newsletter template from Airtable doesn't exist in the database. When sending newsletters, the system now attempts to use the most recent template first, and if that fails, it falls back to one of the previous two templates before raising an error.

Key changes:

  • Fetches up to 3 most recent newsletter template pairs from Airtable instead of just 1
  • Iterates through templates with fallback logic, using the most recent available template in the database
  • Adds warning logs when fallback templates are used and error logs when no valid templates are found

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
app/newsletter/rest.py Implements fallback iteration logic through up to 3 templates with appropriate error handling and logging
app/clients/airtable/models.py Updates get_latest_newsletter_templates to return 3 templates instead of 1
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.

whabanks and others added 3 commits December 10, 2025 18:10
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Since airtable doesn't have a native UUID column type. We cannot
  guarantee that newsletter_template_id_en and fr columns contain only
UUIDs. We need to validate the id's when searching backwards for a valid
newsletter template_id to use when sending the latest newsletter to new
subscribers
This reverts commit 661c25b.
As it was meant to be committed in a different branch.......
This reverts commit 87aa01d.
Turns out this WAS meant for this branch. Brain is scrambled
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.

2 participants