Skip to content

[18.0][FIX] fastapi_log: skip logging when not installed on the request DB - #632

Open
TheClaud99 wants to merge 1 commit into
OCA:18.0from
TheClaud99:18.0-fix-fastapi_log-dispatcher
Open

[18.0][FIX] fastapi_log: skip logging when not installed on the request DB#632
TheClaud99 wants to merge 1 commit into
OCA:18.0from
TheClaud99:18.0-fix-fastapi_log-dispatcher

Conversation

@TheClaud99

Copy link
Copy Markdown

Bug

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.

How to reproduce

Two databases in the same instance:

  • DB Afastapi_log installed
  • DB B — only fastapi installed (no fastapi_log)

As soon as DB A is loaded, its dispatcher is registered process-wide. Any subsequent request to a fastapi endpoint of DB B then crashes with a 500 (AttributeError on log_requests), even though DB B never installed fastapi_log.

Fix

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 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.
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @paradoxxxzero,
some modules you are maintaining are being modified, check this out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants