diff --git a/CHANGELOG.md b/CHANGELOG.md index b960c69..62a8386 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Fix issue where freshness cannot be calculated to re-send request. (#104) +- Update `datetime.datetime.utcnow()` to `datetime.datetime.now(datetime.timezone.utc)` since `datetime.datetime.utcnow()` has been deprecated. (#111) ## 0.0.17 (6/11/2023) diff --git a/hishel/_async/_pool.py b/hishel/_async/_pool.py index c9ab709..b667b0e 100644 --- a/hishel/_async/_pool.py +++ b/hishel/_async/_pool.py @@ -116,7 +116,9 @@ async def handle_async_request(self, request: Request) -> Response: if self._controller.is_cachable(request=request, response=response): await response.aread() - metadata = Metadata(cache_key=key, created_at=datetime.datetime.utcnow(), number_of_uses=0) + metadata = Metadata( + cache_key=key, created_at=datetime.datetime.now(datetime.timezone.utc), number_of_uses=0 + ) await self._storage.store(key, response=response, request=request, metadata=metadata) response.extensions["from_cache"] = False # type: ignore[index] diff --git a/hishel/_async/_transports.py b/hishel/_async/_transports.py index af44866..d62562a 100644 --- a/hishel/_async/_transports.py +++ b/hishel/_async/_transports.py @@ -200,7 +200,9 @@ async def handle_async_request(self, request: Request) -> Response: await httpcore_response.aclose() if self._controller.is_cachable(request=httpcore_request, response=httpcore_response): - metadata = Metadata(cache_key=key, created_at=datetime.datetime.utcnow(), number_of_uses=0) + metadata = Metadata( + cache_key=key, created_at=datetime.datetime.now(datetime.timezone.utc), number_of_uses=0 + ) await self._storage.store( key, response=httpcore_response, diff --git a/hishel/_sync/_pool.py b/hishel/_sync/_pool.py index 7c53d4e..330f5b4 100644 --- a/hishel/_sync/_pool.py +++ b/hishel/_sync/_pool.py @@ -116,7 +116,7 @@ def handle_request(self, request: Request) -> Response: if self._controller.is_cachable(request=request, response=response): response.read() - metadata = Metadata(cache_key=key, created_at=datetime.datetime.utcnow(), number_of_uses=0) + metadata = Metadata(cache_key=key, created_at=datetime.datetime.now(datetime.timezone.utc), number_of_uses=0) self._storage.store(key, response=response, request=request, metadata=metadata) response.extensions["from_cache"] = False # type: ignore[index] diff --git a/hishel/_sync/_transports.py b/hishel/_sync/_transports.py index 7c089a4..c0c5c8a 100644 --- a/hishel/_sync/_transports.py +++ b/hishel/_sync/_transports.py @@ -200,7 +200,7 @@ def handle_request(self, request: Request) -> Response: httpcore_response.close() if self._controller.is_cachable(request=httpcore_request, response=httpcore_response): - metadata = Metadata(cache_key=key, created_at=datetime.datetime.utcnow(), number_of_uses=0) + metadata = Metadata(cache_key=key, created_at=datetime.datetime.now(datetime.timezone.utc), number_of_uses=0) self._storage.store( key, response=httpcore_response, diff --git a/tests/_async/test_storages.py b/tests/_async/test_storages.py index f7be3de..0dadaa5 100644 --- a/tests/_async/test_storages.py +++ b/tests/_async/test_storages.py @@ -8,7 +8,7 @@ from hishel._serializers import Metadata from hishel._utils import asleep, generate_key -dummy_metadata = Metadata(cache_key="test", number_of_uses=0, created_at=datetime.datetime.utcnow()) +dummy_metadata = Metadata(cache_key="test", number_of_uses=0, created_at=datetime.datetime.now(datetime.timezone.utc)) async def is_redis_down() -> bool: diff --git a/tests/_sync/test_storages.py b/tests/_sync/test_storages.py index d390d04..b03062d 100644 --- a/tests/_sync/test_storages.py +++ b/tests/_sync/test_storages.py @@ -8,7 +8,7 @@ from hishel._serializers import Metadata from hishel._utils import sleep, generate_key -dummy_metadata = Metadata(cache_key="test", number_of_uses=0, created_at=datetime.datetime.utcnow()) +dummy_metadata = Metadata(cache_key="test", number_of_uses=0, created_at=datetime.datetime.now(datetime.timezone.utc)) def is_redis_down() -> bool: