gmcquillan / django-brake

Django Brake - a versatile ratelimiting app for Django.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lambda increment functions choke on ratelimited views

jvc26 opened this issue · comments

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

Nice catch. Thanks for the PR, too!

Should this be closed?