From 0d6fc8f7e22f0c77880c5c2e5608964ec553c3a9 Mon Sep 17 00:00:00 2001 From: Hayato Yagi Date: Fri, 20 Sep 2024 18:44:10 +0900 Subject: [PATCH] Add hasattr --- fastapi_limiter/depends.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fastapi_limiter/depends.py b/fastapi_limiter/depends.py index 295df94..0364895 100644 --- a/fastapi_limiter/depends.py +++ b/fastapi_limiter/depends.py @@ -38,7 +38,11 @@ async def __call__(self, request: Request, response: Response): route_index = 0 dep_index = 0 for i, route in enumerate(request.app.routes): - if route.path == request.scope["path"] and request.method in route.methods: + if ( + route.path == request.scope["path"] + and hasattr(route, "methods") + and request.method in route.methods + ): route_index = i for j, dependency in enumerate(route.dependencies): if self is dependency.dependency: