ENG-3301: Align messaging endpoints with service layer pattern#8138
ENG-3301: Align messaging endpoints with service layer pattern#8138JadeCara wants to merge 6 commits intoENG-3301/messaging-provider-refactor-pr2-sesfrom
Conversation
Move dispatch and validation logic from routes into MessagingService: - Add MessagingService.send_test_message() — delegates to dispatch_message - Add MessagingService.validate_provider_on_save() — runs provider validation after secrets save, returns failure reason or None - Add get_provider_class() public accessor to message_dispatch_service (replaces cross-module import of private _PROVIDER_MAP) - Wire route endpoints through MessagingService via Depends() - Fix pre-existing test bug: SES secrets test expected failure_reason=None but validate_on_save correctly rejects fake AWS credentials Routes no longer import _PROVIDER_MAP or call dispatch_message directly (except the deprecated test endpoint which passes str, not enum). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (73.91%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## ENG-3301/messaging-provider-refactor-pr2-ses #8138 +/- ##
================================================================================
- Coverage 83.47% 83.43% -0.05%
================================================================================
Files 643 643
Lines 42112 42130 +18
Branches 4945 4947 +2
================================================================================
- Hits 35153 35151 -2
- Misses 5709 5710 +1
- Partials 1250 1269 +19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…3301/messaging-service-alignment
|
/code-review |
There was a problem hiding this comment.
Code Review — ENG-3301: Align messaging endpoints with service layer pattern
The PR is clean overall. The refactoring correctly moves dispatch_message and _PROVIDER_MAP lookups out of route handlers and into MessagingService, the new get_provider_class public accessor is a straightforward pattern, and the test file is well-structured with good coverage of both success and failure paths.
Issues
1. failure_reason is silently dropped in post_config (moderate)
update_config_secrets now returns a TestMessagingStatusMessage with a failure_reason field, but post_config (line 131–136) discards the return value. Because post_config returns a MessagingConfigResponse, validation failures from validate_provider_on_save are invisible to the caller when creating a config via POST. This should either be documented as intentional (with a comment) or surfaced — e.g., log it at WARN, or add a warning field to the POST response.
2. Uncaught ValueError in validate_provider_on_save (minor)
MessagingServiceType(messaging_config.service_type) will raise ValueError for an unrecognised string. The DB constraint makes this unlikely in production, but it's an unhandled path that would produce a 500. A simple try/except ValueError: return None guard would close it.
3. logger.error removal in aws_ses_service.py (nit)
Dropping duplicate log-before-raise is correct for the save-validation path. Be aware that get_ses_client and validate_email_and_domain_status are also called during real message sends; in that path the failure still propagates, but there's no longer any log at the SES-service level. If that loss of per-method context matters for debugging, a logger.debug call would preserve it without re-introducing the duplicate.
Positives
MessagingService.send_test_messageandvalidate_provider_on_saveare clean thin delegators — exactly the right layer for this logic.- The unit tests cover the key branches (no provider, success, exception) clearly and without over-mocking.
- Fixing the pre-existing test assertion (
failure_reasoncan be non-None with fake SES creds) is the right call. - The
get_provider_classaccessor is a clean way to avoid cross-module private access without changing the_PROVIDER_MAPstructure.
🔬 Codegraph: connected (49514 nodes)
💡 Write /code-review in a comment to re-run this review.
…3301/messaging-service-alignment
When secrets are passed inline during config creation, the validate_on_save result was silently discarded since the response type is MessagingConfigResponse (no failure_reason field). Now logs a warning so the validation failure is visible server-side. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…3301/messaging-service-alignment
Ticket ENG-3301
PR Series
This is PR 2.5 of 3 in the messaging provider refactor:
messaging-provider-refactor-pr1messaging-provider-refactor-pr2-sesmessaging-service-alignmentBase branch:
ENG-3301/messaging-provider-refactor-pr2-ses(PR2)Description Of Changes
Moves leaked dispatch and validation concerns from route endpoints into
MessagingService, aligning with the service/repository pattern.What moved:
dispatch_message()call insend_test_message→MessagingService.send_test_message()_PROVIDER_MAPlookup +validate_on_save()inupdate_config_secrets→MessagingService.validate_provider_on_save()What was added:
get_provider_class()public accessor inmessage_dispatch_service.py(replaces cross-module import of private_PROVIDER_MAP)What was NOT changed (intentional):
send_test_message_deprecatedstill callsdispatch_messagedirectly (passesstr, not enum)dispatch_messagedirectlyCode Changes
src/fides/service/messaging/messaging_service.py— addedsend_test_message(),validate_provider_on_save()src/fides/api/service/messaging/message_dispatch_service.py— addedget_provider_class()public accessorsrc/fides/api/v1/endpoints/messaging_endpoints.py— wired 4 routes throughDepends(get_messaging_service), removed_PROVIDER_MAPimporttests/ops/service/messaging/test_messaging_service.py— 5 new unit teststests/ops/api/v1/endpoints/test_messaging_endpoints.py— fixed pre-existing SES test (expectedfailure_reason=Nonebutvalidate_on_savecorrectly rejects fake creds)Steps to Confirm
pytest tests/ops/service/messaging/test_messaging_service.py -x -q— 5 new tests passpytest tests/ops/api/v1/endpoints/test_messaging_endpoints.py -x -q— all endpoint tests passpytest tests/ops/service/messaging/message_dispatch_service_test.py -x -q— dispatch tests passPOST /api/v1/messaging/test/mailgunstill works viaMessagingServicePUT /api/v1/messaging/default/aws_ses/secretreturnsfailure_reasonon bad creds🤖 Generated with Claude Code