diff --git a/fastapi_log/fastapi_dispatcher.py b/fastapi_log/fastapi_dispatcher.py index f5d3b7ef5..45ffc5d8c 100644 --- a/fastapi_log/fastapi_dispatcher.py +++ b/fastapi_log/fastapi_dispatcher.py @@ -51,7 +51,10 @@ def dispatch(self, endpoint, args): .sudo() ._get_endpoint(environ["PATH_INFO"]) ) - if fastapi_endpoint.log_requests: + # This dispatcher is registered process-wide, so it is also used for + # databases where fastapi_log is not installed. In that case the + # `log_requests` field is not part of the registry, so skip logging. + if "log_requests" in fastapi_endpoint._fields and fastapi_endpoint.log_requests: with self._create_log_env(self.request.env) as log_env: try: log = log_env["api.log"].log_request(self.request)