From 06b34d258f4d103adc68c60c4ffd949a6a92cd27 Mon Sep 17 00:00:00 2001 From: Martin Frost Date: Tue, 31 Mar 2026 22:23:54 +0200 Subject: [PATCH] Apply timezone to parsed `since` timestamp The `datetime.datetime.strptime` function will only return naive timestamps, and those will crash in the database query later if run during times when DST is changing. It can crash with `NonExistantTimeError` when the clock moves forward, and with `AmbiguousTimeError` when the clock moves back. Since we know(?) that we always provide a "UTC" suffix to these timestamps, I think it is safe to hardcode that we add the `timezone.utc` as the tzinfo to these parsed objects. --- app/services/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/views.py b/app/services/views.py index 8c33262..5490290 100644 --- a/app/services/views.py +++ b/app/services/views.py @@ -1,5 +1,5 @@ from base64 import b64decode -from datetime import datetime +from datetime import datetime, timezone from django.contrib.auth.decorators import login_required from django.contrib.auth.hashers import check_password @@ -39,7 +39,7 @@ def passwords(request, name): since = request.GET.get("since") if since: try: - since = datetime.strptime(since, "%Y-%m-%dT%H:%M:%S%Z") + since = datetime.strptime(since, "%Y-%m-%dT%H:%M:%S%Z").astimezone(timezone.utc) except Exception: return JsonResponse({"msg": "Bad date"}, status=400) query = query.filter(modified__gte=since)