From 5c563a71f1e96c6972545b004bb5ad2649d0be5f Mon Sep 17 00:00:00 2001 From: TheClaud99 <39127925+TheClaud99@users.noreply.github.com> Date: Wed, 22 Jul 2026 12:02:55 +0200 Subject: [PATCH] [FIX] fastapi_log: skip logging when not installed on the request DB fastapi_log registers its own FastApiDispatcher through ``odoo.http._dispatchers`` by subclassing the fastapi dispatcher with ``routing_type = "fastapi"``. That registration is process-wide and happens as soon as the module is imported, so once fastapi_log is loaded for a single database its dispatcher handles the fastapi routing of every database served by the same worker process. The dispatcher reads ``fastapi_endpoint.log_requests``, a field this module adds to ``fastapi.endpoint`` through ``api.log_collection.mixin``. On a database where fastapi_log is not installed that field does not exist, so the access raised an ``AttributeError`` and broke every fastapi endpoint of that database. This is easily reproduced with two databases in the same instance: one with fastapi_log installed and one with only fastapi. As soon as the first one is loaded (registering the dispatcher process-wide), any request to a fastapi endpoint of the second one crashed with a 500. Guard the field access with ``"log_requests" in fastapi_endpoint._fields`` so logging only happens when the module is actually installed on the request's database; otherwise fall back to the base dispatch. --- fastapi_log/fastapi_dispatcher.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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)