From fb06d12d5a32581ae531fc26143c14ac6c8ea8fe Mon Sep 17 00:00:00 2001
From: Paul Moore
Date: Tue, 17 Oct 2023 11:04:34 +0100
Subject: [PATCH] Handle ISO formats with a trailing Z
---
news/12338.bugfix.rst | 1 +
src/pip/_internal/self_outdated_check.py | 11 ++++++++++-
2 files changed, 11 insertions(+), 1 deletion(-)
create mode 100644 news/12338.bugfix.rst
diff --git a/news/12338.bugfix.rst b/news/12338.bugfix.rst
new file mode 100644
index 00000000000..cd9a8c10baa
--- /dev/null
+++ b/news/12338.bugfix.rst
@@ -0,0 +1 @@
+Handle a timezone indicator of Z when parsing dates in the self check.
diff --git a/src/pip/_internal/self_outdated_check.py b/src/pip/_internal/self_outdated_check.py
index cb18edbed8e..0f64ae0e614 100644
--- a/src/pip/_internal/self_outdated_check.py
+++ b/src/pip/_internal/self_outdated_check.py
@@ -39,6 +39,15 @@ def _get_statefile_name(key: str) -> str:
return name
+def _convert_date(isodate: str) -> datetime.datetime:
+ """Convert an ISO format string to a date.
+
+ Handles the format 2020-01-22T14:24:01Z (trailing Z)
+ which is not supported by older versions of fromisoformat.
+ """
+ return datetime.datetime.fromisoformat(isodate.replace("Z", "+00:00"))
+
+
class SelfCheckState:
def __init__(self, cache_dir: str) -> None:
self._state: Dict[str, Any] = {}
@@ -73,7 +82,7 @@ def get(self, current_time: datetime.datetime) -> Optional[str]:
return None
# Determine if we need to refresh the state
- last_check = datetime.datetime.fromisoformat(self._state["last_check"])
+ last_check = _convert_date(self._state["last_check"])
time_since_last_check = current_time - last_check
if time_since_last_check > _WEEK:
return None