lambda increment functions choke on ratelimited views
jvc26 opened this issue · comments
James Clemence commented
Currently:
@ratelimit(increment=lambda req, resp: resp.count)
def login(request):
resp = HttpResponseRedirect()
if login_is_correct:
# Do not count correct logins against the limit.
resp.count = False
else:
resp.count = True
return resp
Fails if the ratelimit kicks in:
AttributeError: 'HttpResponseTooManyRequests' object has no attribute 'count'
Ratelimit decorator should not increment, or should not call increment function if the response is a HttpResponseTooManyRequests
object
Gavin McQuillan commented
Nice catch. Thanks for the PR, too!
Stavros Korokithakis commented
Should this be closed?