From 0ca63d1e7c0f5c9bff0065df021dde5958b99d49 Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Wed, 11 Oct 2023 15:40:36 -0400 Subject: [PATCH] fix: make audir log timestamps timezone-aware when needed https://stackoverflow.com/questions/18622007/runtimewarning-datetimefield-received-a-naive-datetime --- terraso_backend/apps/audit_logs/services.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/terraso_backend/apps/audit_logs/services.py b/terraso_backend/apps/audit_logs/services.py index 24a1e963f..7ae6b478a 100644 --- a/terraso_backend/apps/audit_logs/services.py +++ b/terraso_backend/apps/audit_logs/services.py @@ -2,6 +2,7 @@ from datetime import datetime from enum import Enum +from django.conf import settings from django.contrib.contenttypes.models import ContentType from django.core.paginator import Paginator from django.db import transaction @@ -79,7 +80,12 @@ def log( if client_time is None: client_time = datetime.now() - log.client_timestamp = client_time + if settings.USE_TZ: + from django.utils.timezone import make_aware + + log.client_timestamp = make_aware(client_time) + else: + log.client_timestamp = client_time log.metadata = metadata log.save()