Skip to content
This repository was archived by the owner on Apr 14, 2026. It is now read-only.

Commit 06b34d2

Browse files
committed
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.
1 parent d8992ae commit 06b34d2

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

app/services/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from base64 import b64decode
2-
from datetime import datetime
2+
from datetime import datetime, timezone
33

44
from django.contrib.auth.decorators import login_required
55
from django.contrib.auth.hashers import check_password
@@ -39,7 +39,7 @@ def passwords(request, name):
3939
since = request.GET.get("since")
4040
if since:
4141
try:
42-
since = datetime.strptime(since, "%Y-%m-%dT%H:%M:%S%Z")
42+
since = datetime.strptime(since, "%Y-%m-%dT%H:%M:%S%Z").astimezone(timezone.utc)
4343
except Exception:
4444
return JsonResponse({"msg": "Bad date"}, status=400)
4545
query = query.filter(modified__gte=since)

0 commit comments

Comments
 (0)