From 19dff9c2d18ce7d5b48213b42c444c1c7a9980a9 Mon Sep 17 00:00:00 2001 From: loh <55531424+mahoutukaisali@users.noreply.github.com> Date: Thu, 21 Dec 2023 05:31:47 +0900 Subject: [PATCH] Fix twilio_backend.py to send SMS to multiple destinations. (#14656) AWX only sends Twilio notifications to one destination with the current version of code, but this is a bug. Fixed this bug for sending SMS to multiple destinations. --- awx/main/notifications/twilio_backend.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/awx/main/notifications/twilio_backend.py b/awx/main/notifications/twilio_backend.py index 420c5ef74d..34fbff53d4 100644 --- a/awx/main/notifications/twilio_backend.py +++ b/awx/main/notifications/twilio_backend.py @@ -39,11 +39,15 @@ class TwilioBackend(AWXBaseEmailBackend, CustomNotificationBase): logger.error(smart_str(_("Exception connecting to Twilio: {}").format(e))) for m in messages: - try: - connection.messages.create(to=m.to, from_=m.from_email, body=m.subject) - sent_messages += 1 - except Exception as e: - logger.error(smart_str(_("Exception sending messages: {}").format(e))) - if not self.fail_silently: - raise + failed = False + for dest in m.to: + try: + logger.debug(smart_str(_("FROM: {} / TO: {}").format(m.from_email, dest))) + connection.messages.create(to=dest, from_=m.from_email, body=m.subject) + sent_messages += 1 + except Exception as e: + logger.error(smart_str(_("Exception sending messages: {}").format(e))) + failed = True + if not self.fail_silently and failed: + raise return sent_messages