From eaf5ba76cd8657693bcec6dec281a35053b1164b Mon Sep 17 00:00:00 2001 From: Emil Lynegaard Date: Wed, 21 Aug 2024 10:13:27 +0200 Subject: [PATCH 1/2] Bump version and update changelog --- CHANGELOG.md | 2 ++ pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e650180..872ab0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ ### Changed - Breaking change: allow usage of the request object in the except_when function (thanks @colin99d) +- Added more test exemption logic (thanks @colin99) +- Fix logger warning for Python 3.11 deprecation (thanks @kevin868) ## [0.1.9] - 2024-02-05 diff --git a/pyproject.toml b/pyproject.toml index c242b7d..cee0502 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "slowapi" -version = "0.1.9" +version = "0.1.10" description = "A rate limiting extension for Starlette and Fastapi" authors = ["Laurent Savaete "] license = "MIT" From 8bf8b2ec55677aa3c9e0f9bed9f1a48f0b0b8d2e Mon Sep 17 00:00:00 2001 From: Emil Lynegaard Date: Thu, 22 Aug 2024 10:45:08 +0200 Subject: [PATCH 2/2] Make exempt_when with request backwards compatible --- CHANGELOG.md | 2 +- slowapi/extension.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 872ab0c..432633b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Changed -- Breaking change: allow usage of the request object in the except_when function (thanks @colin99d) +- Added: allow usage of the request object in the except_when function (thanks @colin99d) - Added more test exemption logic (thanks @colin99) - Fix logger warning for Python 3.11 deprecation (thanks @kevin868) diff --git a/slowapi/extension.py b/slowapi/extension.py index 050f882..03dc59a 100644 --- a/slowapi/extension.py +++ b/slowapi/extension.py @@ -487,8 +487,12 @@ def __evaluate_limits( limit_for_header = None for lim in limits: limit_scope = lim.scope or endpoint - if lim.is_exempt(request): + if getattr(lim, "_exempt_when_takes_request", False): + if lim.is_exempt(request): + continue + elif lim.is_exempt(): continue + if lim.methods is not None and request.method.lower() not in lim.methods: continue if lim.per_method: