From ac08f000dc74511608b989ce79ae72ee7c03229b Mon Sep 17 00:00:00 2001 From: Florian Aucomte <33633200+faucomte97@users.noreply.github.com> Date: Tue, 19 Sep 2023 00:08:22 +0100 Subject: [PATCH] fix: Disable ratelimit when value is empty (#2178) * fix: Don't run ratelimit on empty key * Disable on value null --- portal/helpers/ratelimit.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/portal/helpers/ratelimit.py b/portal/helpers/ratelimit.py index 1787e73b9..acf108842 100644 --- a/portal/helpers/ratelimit.py +++ b/portal/helpers/ratelimit.py @@ -161,7 +161,16 @@ def get_usage(request, group=None, fn=None, key=None, rate=None, method=ALL, inc cache_name = getattr(settings, "RATELIMIT_USE_CACHE", "default") cache = caches[cache_name] - cache_key = _make_cache_key(group, window, rate, value, method) + + if value == "": + return { + "count": 0, + "limit": 0, + "should_limit": False, + "time_left": -1, + } + else: + cache_key = _make_cache_key(group, window, rate, value, method) count = None added = cache.add(cache_key, initial_value, period + EXPIRATION_FUDGE)