This morning we raise a ParseError for a bad date format for the DateReceived attribute on the /notifications/receive/mmg request.

This PR tries to parse the date, if that throws an error return now as the datereceived. This will at least allow the message to be persisted. Typically the DateReceived, provider_date, and the created_at date in the inbound_sms table are within a second of each other.
This commit is contained in:
Rebecca Law
2020-05-13 10:37:41 +01:00
parent 2f8947afde
commit aecf17fef1
2 changed files with 13 additions and 3 deletions

View File

@@ -1,3 +1,4 @@
from datetime import datetime
from urllib.parse import unquote
import iso8601
@@ -115,9 +116,12 @@ def format_mmg_datetime(date):
We expect datetimes in format 2017-05-21+11%3A56%3A11 - ie, spaces replaced with pluses, and URI encoded
and in UTC
"""
orig_date = format_mmg_message(date)
parsed_datetime = iso8601.parse_date(orig_date).replace(tzinfo=None)
return parsed_datetime
try:
orig_date = format_mmg_message(date)
parsed_datetime = iso8601.parse_date(orig_date).replace(tzinfo=None)
return parsed_datetime
except iso8601.ParseError:
return datetime.utcnow()
def create_inbound_sms_object(service, content, from_number, provider_ref, date_received, provider_name):