Cast oldest[0][1] to float in RedisSlidingWindow fallback
CI / lint (pull_request) Successful in 5s
CI / typecheck (pull_request) Successful in 27s
CI / test (pull_request) Successful in 35s
CI / build-and-push (pull_request) Failing after 7s

mypy complained: 'Unsupported operand types for - ("str" and "float")'
on rate_limit.py:87. redis-py's zrange withscores=True returns the
score as whatever the codec produces (often str), but we treat it as
a numeric millisecond timestamp. Cast to float before subtracting
the cutoff.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Barcode Betty
2026-06-02 13:48:26 +00:00
parent e1b47a30c6
commit 83ee3e814b
+1 -1
View File
@@ -84,7 +84,7 @@ class RedisSlidingWindow:
if current_count >= self.max_requests:
oldest = await self.redis.zrange(key, 0, 0, withscores=True)
if oldest:
retry_after = int((oldest[0][1] - cutoff) / 1000) + 1
retry_after = int((float(oldest[0][1]) - cutoff) / 1000) + 1
else:
retry_after = self.window_seconds
return False, 0, retry_after