From 4744e876c7cc98b0156ba6e5745db781873ac879 Mon Sep 17 00:00:00 2001 From: Martin Indra Date: Sun, 21 Feb 2021 11:40:54 +0100 Subject: [PATCH] Fix date parsing in Azure Table entities This fixes the following error: ValueError: time data '2021-02-21T10:14:42.879Z' does not match format '%Y-%m-%dT%H:%M:%SZ' --- .../azure-data-tables/azure/data/tables/_deserialize.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sdk/tables/azure-data-tables/azure/data/tables/_deserialize.py b/sdk/tables/azure-data-tables/azure/data/tables/_deserialize.py index 86f4df027911..4dddab0c8d17 100644 --- a/sdk/tables/azure-data-tables/azure/data/tables/_deserialize.py +++ b/sdk/tables/azure-data-tables/azure/data/tables/_deserialize.py @@ -96,8 +96,12 @@ def tzname(self, dt): def _from_entity_datetime(value): # Cosmos returns this with a decimal point that throws an error on deserialization - if value[-9:] == ".0000000Z": - value = value[:-9] + "Z" + for suffix_len in (5, 9): + suffix = "." + ("0" * (suffix_len - 2)) + "Z" + if value[-suffix_len:] == suffix: + value = value[:-suffix_len] + "Z" + break + return datetime.datetime.strptime(value, "%Y-%m-%dT%H:%M:%SZ").replace( tzinfo=Timezone() )