From 549669e1b590e9152c2d4e1d3ec4359822b1e27b Mon Sep 17 00:00:00 2001 From: Aymen-Mohammednur Date: Mon, 2 Sep 2024 10:42:58 +0300 Subject: [PATCH] Fix issue with sorting --- g2p_odk_importer/models/odk_client.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/g2p_odk_importer/models/odk_client.py b/g2p_odk_importer/models/odk_client.py index da4b2f2..5d36dbc 100644 --- a/g2p_odk_importer/models/odk_client.py +++ b/g2p_odk_importer/models/odk_client.py @@ -89,12 +89,13 @@ def import_delta_records(self, last_sync_timestamp=None, skip=0, top=100): _logger.exception("Failed to parse response: %s", e) raise ValidationError(f"Failed to parse response: {e}") from e - # Sort the list of submissions based on the submission_time field + # Sort the list of submissions based on the submission_time field if it exists data["value"] = sorted( data["value"], - key=lambda x: parser.parse(x["submission_time"]) - if x.get("submission_time") not in (None, "") - else None, + key=lambda x: ( + x.get("submission_time") in (None, ""), # True for invalid times, sorts to end + parser.parse(x["submission_time"]) if x.get("submission_time") not in (None, "") else None, + ), ) for member in data["value"]: