From e211b11ac6ca459b2ac947a7728ad548b1bd4978 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Thu, 19 Sep 2024 16:17:19 +0100 Subject: [PATCH] hopefully fix it once and for all --- sentry_sdk/scope.py | 1 - sentry_sdk/utils.py | 11 ++++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 8dae09f44b..7dabb7035e 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -1325,7 +1325,6 @@ def _apply_breadcrumbs_to_event(self, event, hint, options): event["breadcrumbs"]["values"].sort(key=lambda crumb: crumb["timestamp"]) except Exception as err: - print(err) logger.warning("Error when sorting breadcrumbs", exc_info=err) pass diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index 6608c6ed78..f98708640b 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -243,15 +243,20 @@ def datetime_from_isoformat(value): # type: (str) -> datetime try: return datetime.fromisoformat(value) - except AttributeError: + except (AttributeError, ValueError): # py 3.6 timestamp_format = ( "%Y-%m-%dT%H:%M:%S.%f" if "." in value else "%Y-%m-%dT%H:%M:%S" ) if value.endswith("Z"): value = value[:-1] - elif "+" in value: - timestamp_format += "%z" + else: + plus_idx = value.rfind("+") + if plus_idx != -1: + tz_colon_index = value.rfind(":", plus_idx) + if tz_colon_index != -1: + value = value[:tz_colon_index] + value[tz_colon_index + 1 :] + timestamp_format += "%z" return datetime.strptime(value, timestamp_format)