feat: Add Brevo list update as part of migrate_firebase_users & consistent update brevo list#1772
Open
davidgamez wants to merge 7 commits into
Open
feat: Add Brevo list update as part of migrate_firebase_users & consistent update brevo list#1772davidgamez wants to merge 7 commits into
davidgamez wants to merge 7 commits into
Conversation
5 tasks
Member
Author
davidgamez
marked this pull request as ready for review
July 24, 2026 14:47
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Summary:
This PR updates the Firebase migration script by adding the MDB_SUBSCRIPTION_ID to Brevo per user. Uses brevo_synced_at to mark users as already synced.
To complete the Brevo announcements configuration, it also updates the is_registered_to_receive_api_announcements function to add/remove users from the Brevo list. This replaces the monthly manual imports and keeps the list up to date with the latest subscriptions.
From our AI friend
This pull request introduces a unified and consistent approach for managing a user's opt-in status for API announcements, ensuring that the database, notification subscriptions, and Brevo (email provider) are always kept in sync. The core logic is centralized in a new helper function, and all relevant API endpoints and tests are updated to use this logic. Additionally, the Firebase migration documentation and logic are improved to clarify the handling of Brevo synchronization and the
brevo_synced_atfield.Announcement opt-in synchronization improvements:
set_announcements_optininsubscription_helpers.py, which atomically reconciles a user's announcements subscription, Brevo list membership, and theis_registered_to_receive_api_announcementsflag, handling both subscribe and unsubscribe flows and ensuring all representations are consistent.users_api_impl.pyandsubscriptions_api_impl.py) to useset_announcements_optininstead of directly manipulating subscriptions or making Brevo calls, including proper handling of DB transactions and connection pooling for slow providers. [1] [2] [3] [4] [5] [6]Firebase migration logic and documentation:
migrate_firebase_userstask, describing the new logic for backfilling notification subscriptions, writingMDB_SUBSCRIPTION_IDto Brevo contacts, and updating thebrevo_synced_atfield only after successful synchronization. New result counters are documented. [1] [2] [3]brevo_synced_atis now the only field updated on existing users, and to highlight the idempotent Brevo write-back logic.Codebase cleanup and consistency:
sync_announcementswith the newset_announcements_optinhelper in both implementation files and imports, ensuring a single point of truth for the synchronization logic. [1] [2]These changes close historical bugs where the user's opt-in flag, notification subscription, and Brevo list membership could become inconsistent, and ensure all future updates remain atomic and reliable.
Expected behavior:
Explain and/or show screenshots for how you expect the pull request to work in your testing (in case other devices exhibit different behavior).
Testing tips:
Provide tips, procedures and sample files on how to test the feature.
Testers are invited to follow the tips AND to try anything they deem relevant outside the bounds of the testing tips.
Testing tips
Registration / profile opt-in (user_service)
PUT /v1/userwithis_registered_to_receive_api_announcements: true→ check:api.announcementssubscription row created, contact added to the Brevo list withMDB_SUBSCRIPTION_IDset, and the profile flag istrue.false→ contact removed from the list, subscription disabled (not deleted), flagfalse.full_name) → no Brevo call.Migration task (
migrate_firebase_users, #1733)dry_run: true→ checkbrevo_synced/brevo_sync_failedcounts, no writes.dry_run: false(start with a smalllimit) →SUBSCRIBEDcontacts getMDB_SUBSCRIPTION_ID,app_user.brevo_synced_atis stamped.UNSUBSCRIBED/NOT_FOUNDcontacts are never added to the list.Please make sure these boxes are checked before submitting your pull request - thanks!
./scripts/api-tests.shto make sure you didn't break anything