Report Connect Message send failures in messaging reports - #38091
Open
ajeety4 wants to merge 5 commits into
Open
Report Connect Message send failures in messaging reports#38091ajeety4 wants to merge 5 commits into
ajeety4 wants to merge 5 commits into
Conversation
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Issue: ConnectBackend.send returned False for a non-200 response from the Connect messaging API, send_connect_message discarded that return value, and the subevent was never resolved. A rejected send was reported as success, and the response body was lost. Fix: raise from the backend with the status code and body, record it on the subevent, and complete the subevent on success — the pattern SMSContent and EmailContent already follow. log_sms_exception assumed msg.couch_id, which ConnectMessage does not have, so the existing error path raised AttributeError instead of logging. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ConnectMessageContent.send passed no metadata, so add_msg_tags left ConnectMessage.messaging_subevent NULL. The event detail report looks the message up by that FK, so Content and ConnectID always rendered as '-'. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
send_connect_message labelled every exception ERROR_CONNECT_GATEWAY, so a missing ConnectIDUserLink or an absent couch user was reported to the user as a gateway problem. Map the exception to an error code instead. The backend now also wraps requests.RequestException, so a network failure still reports as a gateway error rather than an internal one. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ConnectMessageContent.send hardcoded case_id=None, so a conditional alert sending a Connect message lost the case association on its subevent. Take it from self.case, as SMSContent and EmailContent do. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ajeety4
force-pushed
the
ay/connect-messaging-fixes
branch
from
September 3, 2026 08:23
4e6bc71 to
69bdb14
Compare
ajeety4
marked this pull request as ready for review
September 3, 2026 08:28
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.
Product Description
No user facing change.
Bug fixes to the Connect Message path: a send rejected by the Connect API is now recorded as an error on the messaging event instead of being reported as completed, and the Message Event Detail page renders Connect Message rows instead of erroring.
Technical Summary
https://dimagi.atlassian.net/browse/CI-910 - Observed while working on this ticket
Six issues in the Connect Message path:
MessageEventDetailReport.rowsdereferencedmsgafterConnectMessage.DoesNotExist, and never initialisedrecipient.Fix: initialise the placeholders before the lookup, as the
CONTENT_EMAILbranch does.ConnectBackend.sendreturned a bool thatsend_connect_messagediscarded, so a rejected send reported success — the subevent stayedIN_PROGRESSand the parent event was markedCOMPLETED.Fix: the backend raises
BackendProcessingExceptionwith the status code and body,send_connect_messageerrors the subevent, andConnectMessageContent.sendcompletes it.ConnectMessage.messaging_subeventwas never set, so the detail report's lookup always missed — why 1 (above point 1) was reachable at all.Fix: pass
get_sms_message_metadata(logged_subevent), asSMSContentdoes.log_sms_exceptionreadsmsg.couch_id, whichConnectMessagedoesn't have, so real exceptions raisedAttributeErrorinstead of logging.Fix: fall back to
message_id.ERROR_CONNECT_GATEWAY, including a missingConnectIDUserLinkor absent couch user.Fix:
get_connect_error_codemaps by exception type; the backend wrapsRequestExceptionso network failures still count as gateway errors.ConnectMessageContenthardcodedcase_id=None, losing the case association on its subevent.Fix: take it from
self.case.ConnectMessageSurveyContentneeds no change — it sends viasend_first_message, which already passes bothmetadataandlogged_subevent.Feature Flag
COMMCARE_CONNECTSafety Assurance
Safety story
Low risk, scoped to the
CONTENT_CONNECTpath. No migrations.ConnectBackend.sendnow raises where it returnedFalse; its only caller already caughtException, so nothing new escapes.ERROR_CONNECT_GATEWAYis a new value in aCharFieldwith no choices constraint, so existing rows are unaffected.Verified on a local dev domain against all four row shapes — delivered with and without a linked message, gateway 400 with and without one.
Automated test coverage
corehq/apps/reports/tests/test_message_event_detail_report.py— detail rows with and without a linkedConnectMessage; the second reproduces theUnboundLocalError.corehq/messaging/scheduling/tests/test_content.py::TestConnectMessageContentSend— subevent completed on a 200, errored with the response body on a 400 and propagated to the parent event, message linked to the subevent, case recorded.corehq/apps/sms/tests/test_api.py—get_connect_error_codeover all three exception classes.Each test was confirmed to fail on the unfixed code.
QA Plan
None
Rollback instructions
Labels & Review