From 2f2706a9e6eadaa1ef6da48b9675a26be607f683 Mon Sep 17 00:00:00 2001 From: Fridolin Glatter Date: Thu, 8 Feb 2024 11:51:17 +0100 Subject: [PATCH] Resolve datetime deprecation warnings --- ixmp4/data/db/base.py | 7 +++++-- ixmp4/server/rest/__init__.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ixmp4/data/db/base.py b/ixmp4/data/db/base.py index c9587e5a..a476fb6c 100644 --- a/ixmp4/data/db/base.py +++ b/ixmp4/data/db/base.py @@ -1,6 +1,6 @@ import logging import sqlite3 -from datetime import datetime +from datetime import datetime, timezone from typing import ( TYPE_CHECKING, Any, @@ -116,7 +116,10 @@ def get(self, *args, **kwargs) -> ModelType: class Creator(BaseRepository[ModelType], abstract.Creator): def get_creation_info(self) -> dict: - info = {"created_at": datetime.utcnow(), "created_by": "@unknown"} + info = { + "created_at": datetime.now(tz=timezone.utc), + "created_by": "@unknown", + } if self.backend.auth_context is not None: info["created_by"] = self.backend.auth_context.user.username return info diff --git a/ixmp4/server/rest/__init__.py b/ixmp4/server/rest/__init__.py index 85c833be..307be244 100644 --- a/ixmp4/server/rest/__init__.py +++ b/ixmp4/server/rest/__init__.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, timezone from fastapi import Depends, FastAPI, Path, Request from fastapi.encoders import jsonable_encoder @@ -69,7 +69,7 @@ def root( version=version, is_managed=settings.managed, manager_url=str(settings.manager_url), - utcnow=datetime.utcnow(), + utcnow=datetime.now(tz=timezone.utc), )