From 466113e6cb9e6510446a7747c81aadd1b5c7f630 Mon Sep 17 00:00:00 2001 From: Peter Pfeufer Date: Fri, 26 Sep 2025 17:09:35 +0200 Subject: [PATCH 1/2] [FIX] Calls to deprecated `utcnow` method of `datetime.datetime` datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC). ```python @classmethod @deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .now(datetime.UTC)") def utcnow(cls) -> Self ``` --- allianceauth/authentication/task_statistics/counters.py | 2 +- allianceauth/authentication/task_statistics/event_series.py | 2 +- allianceauth/services/modules/openfire/views.py | 4 ++-- allianceauth/services/modules/phpbb3/manager.py | 4 ++-- allianceauth/services/modules/smf/manager.py | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/allianceauth/authentication/task_statistics/counters.py b/allianceauth/authentication/task_statistics/counters.py index bdb6d034..bdc2d398 100644 --- a/allianceauth/authentication/task_statistics/counters.py +++ b/allianceauth/authentication/task_statistics/counters.py @@ -27,7 +27,7 @@ def dashboard_results(hours: int) -> _TaskCounts: my_earliest = events.first_event(earliest=earliest) return [my_earliest] if my_earliest else [] - earliest = dt.datetime.utcnow() - dt.timedelta(hours=hours) + earliest = dt.datetime.now(dt.timezone.utc) - dt.timedelta(hours=hours) earliest_events = [] succeeded_count = succeeded_tasks.count(earliest=earliest) earliest_events += earliest_if_exists(succeeded_tasks, earliest) diff --git a/allianceauth/authentication/task_statistics/event_series.py b/allianceauth/authentication/task_statistics/event_series.py index 9ac1f15d..016ba68d 100644 --- a/allianceauth/authentication/task_statistics/event_series.py +++ b/allianceauth/authentication/task_statistics/event_series.py @@ -42,7 +42,7 @@ class EventSeries: - event_time: timestamp of event. Will use current time if not specified. """ if not event_time: - event_time = dt.datetime.utcnow() + event_time = dt.datetime.now(dt.timezone.utc) my_id = self._redis.incr(self._key_counter) self._redis.zadd(self._key_sorted_set, {my_id: event_time.timestamp()}) diff --git a/allianceauth/services/modules/openfire/views.py b/allianceauth/services/modules/openfire/views.py index b07e12fa..fe0694c8 100644 --- a/allianceauth/services/modules/openfire/views.py +++ b/allianceauth/services/modules/openfire/views.py @@ -100,13 +100,13 @@ def jabber_broadcast_view(request): if main_char is not None: message_to_send = form.cleaned_data['message'] + "\n##### SENT BY: " + "[" + main_char.corporation_ticker + "]" + \ main_char.character_name + " TO: " + \ - form.cleaned_data['group'] + " WHEN: " + datetime.datetime.utcnow().strftime( + form.cleaned_data['group'] + " WHEN: " + datetime.datetime.now(datetime.timezone.utc).strftime( "%Y-%m-%d %H:%M:%S") + " #####\n##### Replies are NOT monitored #####\n" group_to_send = form.cleaned_data['group'] else: message_to_send = form.cleaned_data['message'] + "\n##### SENT BY: " + "No character but can send pings?" + " TO: " + \ - form.cleaned_data['group'] + " WHEN: " + datetime.datetime.utcnow().strftime( + form.cleaned_data['group'] + " WHEN: " + datetime.datetime.now(datetime.timezone.utc).strftime( "%Y-%m-%d %H:%M:%S") + " #####\n##### Replies are NOT monitored #####\n" group_to_send = form.cleaned_data['group'] diff --git a/allianceauth/services/modules/phpbb3/manager.py b/allianceauth/services/modules/phpbb3/manager.py index 7e6120a6..6937cbac 100644 --- a/allianceauth/services/modules/phpbb3/manager.py +++ b/allianceauth/services/modules/phpbb3/manager.py @@ -2,7 +2,7 @@ import random import string import calendar import re -from datetime import datetime +import datetime as dt from passlib.apps import phpbb3_context from django.db import connections @@ -128,7 +128,7 @@ class Phpbb3Manager: @staticmethod def __get_current_utc_date(): - d = datetime.utcnow() + d = dt.datetime.now(dt.timezone.utc) unixtime = calendar.timegm(d.utctimetuple()) return unixtime diff --git a/allianceauth/services/modules/smf/manager.py b/allianceauth/services/modules/smf/manager.py index 9a3d7049..f810e760 100644 --- a/allianceauth/services/modules/smf/manager.py +++ b/allianceauth/services/modules/smf/manager.py @@ -1,7 +1,7 @@ import random import string import calendar -from datetime import datetime +import datetime as dt import hashlib import logging import re @@ -105,7 +105,7 @@ class SmfManager: @staticmethod def get_current_utc_date(): - d = datetime.utcnow() + d = dt.datetime.now(dt.timezone.utc) unixtime = calendar.timegm(d.utctimetuple()) return unixtime From e5f3a6791925deb7a4a900937a2d50ca73338f00 Mon Sep 17 00:00:00 2001 From: Peter Pfeufer Date: Fri, 26 Sep 2025 17:09:35 +0200 Subject: [PATCH 2/2] [FIX] Calls to deprecated `utcnow` method of `datetime.datetime` datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC). ```python @classmethod @deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .now(datetime.UTC)") def utcnow(cls) -> Self ``` --- allianceauth/authentication/task_statistics/counters.py | 2 +- allianceauth/authentication/task_statistics/event_series.py | 2 +- allianceauth/services/modules/openfire/views.py | 4 ++-- allianceauth/services/modules/phpbb3/manager.py | 4 ++-- allianceauth/services/modules/smf/manager.py | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/allianceauth/authentication/task_statistics/counters.py b/allianceauth/authentication/task_statistics/counters.py index bdb6d034..bdc2d398 100644 --- a/allianceauth/authentication/task_statistics/counters.py +++ b/allianceauth/authentication/task_statistics/counters.py @@ -27,7 +27,7 @@ def dashboard_results(hours: int) -> _TaskCounts: my_earliest = events.first_event(earliest=earliest) return [my_earliest] if my_earliest else [] - earliest = dt.datetime.utcnow() - dt.timedelta(hours=hours) + earliest = dt.datetime.now(dt.timezone.utc) - dt.timedelta(hours=hours) earliest_events = [] succeeded_count = succeeded_tasks.count(earliest=earliest) earliest_events += earliest_if_exists(succeeded_tasks, earliest) diff --git a/allianceauth/authentication/task_statistics/event_series.py b/allianceauth/authentication/task_statistics/event_series.py index 9ac1f15d..016ba68d 100644 --- a/allianceauth/authentication/task_statistics/event_series.py +++ b/allianceauth/authentication/task_statistics/event_series.py @@ -42,7 +42,7 @@ class EventSeries: - event_time: timestamp of event. Will use current time if not specified. """ if not event_time: - event_time = dt.datetime.utcnow() + event_time = dt.datetime.now(dt.timezone.utc) my_id = self._redis.incr(self._key_counter) self._redis.zadd(self._key_sorted_set, {my_id: event_time.timestamp()}) diff --git a/allianceauth/services/modules/openfire/views.py b/allianceauth/services/modules/openfire/views.py index b07e12fa..fe0694c8 100644 --- a/allianceauth/services/modules/openfire/views.py +++ b/allianceauth/services/modules/openfire/views.py @@ -100,13 +100,13 @@ def jabber_broadcast_view(request): if main_char is not None: message_to_send = form.cleaned_data['message'] + "\n##### SENT BY: " + "[" + main_char.corporation_ticker + "]" + \ main_char.character_name + " TO: " + \ - form.cleaned_data['group'] + " WHEN: " + datetime.datetime.utcnow().strftime( + form.cleaned_data['group'] + " WHEN: " + datetime.datetime.now(datetime.timezone.utc).strftime( "%Y-%m-%d %H:%M:%S") + " #####\n##### Replies are NOT monitored #####\n" group_to_send = form.cleaned_data['group'] else: message_to_send = form.cleaned_data['message'] + "\n##### SENT BY: " + "No character but can send pings?" + " TO: " + \ - form.cleaned_data['group'] + " WHEN: " + datetime.datetime.utcnow().strftime( + form.cleaned_data['group'] + " WHEN: " + datetime.datetime.now(datetime.timezone.utc).strftime( "%Y-%m-%d %H:%M:%S") + " #####\n##### Replies are NOT monitored #####\n" group_to_send = form.cleaned_data['group'] diff --git a/allianceauth/services/modules/phpbb3/manager.py b/allianceauth/services/modules/phpbb3/manager.py index 7e6120a6..6937cbac 100644 --- a/allianceauth/services/modules/phpbb3/manager.py +++ b/allianceauth/services/modules/phpbb3/manager.py @@ -2,7 +2,7 @@ import random import string import calendar import re -from datetime import datetime +import datetime as dt from passlib.apps import phpbb3_context from django.db import connections @@ -128,7 +128,7 @@ class Phpbb3Manager: @staticmethod def __get_current_utc_date(): - d = datetime.utcnow() + d = dt.datetime.now(dt.timezone.utc) unixtime = calendar.timegm(d.utctimetuple()) return unixtime diff --git a/allianceauth/services/modules/smf/manager.py b/allianceauth/services/modules/smf/manager.py index 9a3d7049..f810e760 100644 --- a/allianceauth/services/modules/smf/manager.py +++ b/allianceauth/services/modules/smf/manager.py @@ -1,7 +1,7 @@ import random import string import calendar -from datetime import datetime +import datetime as dt import hashlib import logging import re @@ -105,7 +105,7 @@ class SmfManager: @staticmethod def get_current_utc_date(): - d = datetime.utcnow() + d = dt.datetime.now(dt.timezone.utc) unixtime = calendar.timegm(d.utctimetuple()) return unixtime