Skip to content

ENG-3301: Refactor messaging dispatchers into provider classes (Story 1)#7947

Closed
JadeCara wants to merge 3 commits intomainfrom
ENG-3301/messaging-provider-refactor
Closed

ENG-3301: Refactor messaging dispatchers into provider classes (Story 1)#7947
JadeCara wants to merge 3 commits intomainfrom
ENG-3301/messaging-provider-refactor

Conversation

@JadeCara
Copy link
Copy Markdown
Contributor

Ticket ENG-3301

Description Of Changes

Refactors the function-based dispatcher pattern in message_dispatch_service.py (~315 lines removed) into provider classes behind a two-level ABC hierarchy. This is PR 1 of 3 for ENG-3301 — it covers the structural refactor only (Story 1). Threading headers (Story 2) and correspondence scaffolding (Story 3) follow in separate PRs.

What changed:

  • New ABC hierarchy: BaseMessageProviderServiceBaseEmailProviderService / BaseSMSProviderService
  • 5 provider classes replace the old _*_dispatcher functions: MailgunService, TwilioEmailService, AwsSesService, MailchimpTransactionalService, TwilioSmsService
  • PROVIDER_MAP routes MessagingServiceType → provider class
  • dispatch_message() signature is unchanged — all callers (fides + fidesplus) are unaffected

Intentional behavioral improvement:

  • SES validate_email_and_domain_status() moved from per-send to config-time (advisory warning in update_config_secrets). SES itself rejects sends from unverified identities (MessageRejected), making the per-send check redundant. See plan Decision Port CI from GitLab CI to GitHub Actions #11 for rationale.

Test improvements:

  • SES tests rewritten with moto[ses] instead of unittest.mock patches — exercises real boto3 client construction through moto
  • Added moto[ses] to dev dependencies (moto[s3]moto[s3,ses])

Reference: Based on patterns from Eli Rosselli's LJ-352-improvements branch (~Feb 2025, never merged), with divergences documented in the technical plan.

Code Changes

  • New: src/fides/api/service/messaging/messaging_providers/ package — ABC base + 5 provider classes
  • Modified: message_dispatch_service.py — replaced dispatcher functions with PROVIDER_MAP + _resolve_provider_map(), deleted ~315 lines
  • Modified: messaging_endpoints.py — wired advisory SES validation into update_config_secrets()
  • Deleted: src/fides/service/messaging/aws_ses_service.py — replaced by new AwsSesService provider
  • Modified: pyproject.tomlmoto[s3]moto[s3,ses]
  • Updated: 8 test files — mock paths updated from old _*_dispatcher functions to new provider classes

Steps to Confirm

  1. All existing messaging tests pass unchanged (104 tests in tests/ops/service/messaging/ + tests/service/messaging/)
  2. Integration test files (test_integration_dynamic_erasure_email.py, test_integration_attentive.py, test_integration_generic_email.py) collect without import errors
  3. dispatch_message() signature unchanged — verify no fidesplus import breakage
  4. SES config-time validation: saving SES config secrets logs a warning if identity not verified (advisory, non-blocking)

Pre-Merge Checklist

  • Issue requirements met
  • All CI pipelines succeeded
  • CHANGELOG.md updated
    • Add a db-migration This indicates that a change includes a database migration label to the entry if your change includes a DB migration
    • Add a high-risk This issue suggests changes that have a high-probability of breaking existing code label to the entry if your change includes a high-risk change (i.e. potential for performance impact or unexpected regression) that should be flagged
    • Updates unreleased work already in Changelog, no new entry necessary
  • UX feedback:
    • All UX related changes have been reviewed by a designer
    • No UX review needed
  • Followup issues:
    • Followup issues created
    • No followup issues
  • Database migrations:
    • Ensure that your downrev is up to date with the latest revision on main
    • Ensure that your downgrade() migration is correct and works
      • If a downgrade migration is not possible for this change, please call this out in the PR description!
    • No migrations
  • Documentation:
    • Documentation complete, PR opened in fidesdocs
    • Documentation issue created in fidesdocs
    • If there are any new client scopes created as part of the pull request, remember to update public-facing documentation that references our scope registry
    • No documentation updates required

JadeCara and others added 2 commits April 16, 2026 11:17
Replace the function-based dispatcher pattern in message_dispatch_service.py
with provider classes behind a two-level ABC hierarchy:

- BaseMessageProviderService → BaseEmailProviderService / BaseSMSProviderService
- 5 provider classes: MailgunService, TwilioEmailService, AwsSesService,
  MailchimpTransactionalService, TwilioSmsService
- PROVIDER_MAP routes MessagingServiceType to provider classes
- dispatch_message() signature unchanged — all callers unaffected

Key changes:
- Delete ~315 lines of old dispatcher functions, validate_config, and helpers
- Move SES validate_email_and_domain_status() from per-send to config-time
  (advisory warning in update_config_secrets, not blocking)
- Delete old src/fides/service/messaging/aws_ses_service.py
- TwilioSmsService overrides validate_config() for secrets-only validation
- SES tests rewritten with moto[ses] instead of unittest.mock patches
- Add moto[ses] to dev dependencies

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
fides-plus-nightly Ignored Ignored Preview Apr 16, 2026 7:02pm
fides-privacy-center Ignored Ignored Apr 16, 2026 7:02pm

Request Review

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 16, 2026

Dependency Review

✅ No vulnerabilities found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA 0a01ec0.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 16, 2026

Codecov Report

❌ Patch coverage is 74.79339% with 61 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.13%. Comparing base (c6fe17d) to head (0a01ec0).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
...saging/messaging_providers/twilio_email_service.py 64.00% 18 Missing ⚠️
...aging_providers/mailchimp_transactional_service.py 42.30% 15 Missing ⚠️
...e/messaging/messaging_providers/mailgun_service.py 77.14% 6 Missing and 2 partials ⚠️
.../api/service/messaging/message_dispatch_service.py 68.18% 3 Missing and 4 partials ⚠️
...essaging/messaging_providers/twilio_sms_service.py 81.25% 4 Missing and 2 partials ⚠️
src/fides/api/v1/endpoints/messaging_endpoints.py 14.28% 5 Missing and 1 partial ⚠️
...e/messaging/messaging_providers/aws_ses_service.py 98.11% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (74.79%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.
❌ Your project check has failed because the head coverage (84.13%) is below the target coverage (85.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7947      +/-   ##
==========================================
- Coverage   85.06%   84.13%   -0.94%     
==========================================
  Files         629      634       +5     
  Lines       40860    41045     +185     
  Branches     4748     4768      +20     
==========================================
- Hits        34759    34533     -226     
- Misses       5029     5365     +336     
- Partials     1072     1147      +75     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Constant was only used by deleted dispatcher functions. Test import
updated to pull from twilio_email_service where it's actively used.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JadeCara
Copy link
Copy Markdown
Contributor Author

JadeCara commented May 6, 2026

Superseded by #8118 (4 providers) and #8120 (AWS SES). Split into two smaller PRs.

@JadeCara JadeCara closed this May 6, 2026
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.

1 participant