fix frozen time bounds on the recordings API (#24121)

`after` and `before` defaulted to `datetime.now()` in the function signature, so they were evaluated once at import. Requests that omitted them got a window ending at process start. They now resolve in the handler.
This commit is contained in:
Josh Hawkins
2026-09-12 07:30:04 -06:00
committed by Nicolas Mowen
parent e2da7aae99
commit 9416e74aeb
4 changed files with 38 additions and 10 deletions
+23 -1
View File
@@ -1,7 +1,8 @@
"""Unit tests for recordings/media API endpoints."""
from dataclasses import dataclass
from datetime import UTC, datetime
from datetime import UTC, datetime, timedelta
from unittest.mock import patch
import pytz
from fastapi import Request
@@ -1838,6 +1839,27 @@ class TestHttpMedia(BaseTestHttp):
recording["id"] for recording in response.json()
] == expected_ids
def test_recordings_default_range_follows_the_request_clock(self):
"""Omitted bounds resolve at request time, not at module import time."""
uptime = timedelta(hours=2)
recorded_at = (datetime.now() + uptime).timestamp()
class UptimeDatetime(datetime):
"""Stands in for a process that booted `uptime` ago."""
@classmethod
def now(cls, tz=None):
return datetime.now(tz) + uptime
with AuthTestClient(self.app) as client:
self._insert_recording("after_boot", recorded_at - 20, recorded_at - 10)
with patch("frigate.api.record.datetime", UptimeDatetime):
response = client.get("/front_door/recordings")
assert response.status_code == 200
assert [recording["id"] for recording in response.json()] == ["after_boot"]
def test_vod_handles_all_range_relations(self):
"""VOD clips every interval relation with positive playback duration."""
with AuthTestClient(self.app) as client: