[18.0][FIX] fastapi_log: skip logging when not installed on the request DB - #632
Open
TheClaud99 wants to merge 1 commit into
Open
[18.0][FIX] fastapi_log: skip logging when not installed on the request DB#632TheClaud99 wants to merge 1 commit into
TheClaud99 wants to merge 1 commit into
Conversation
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.
Contributor
|
Hi @paradoxxxzero, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
fastapi_logregisters its ownFastApiDispatcherthroughodoo.http._dispatchersby subclassing the fastapi dispatcher withrouting_type = "fastapi". That registration is process-wide and happens as soon as the module is imported, so oncefastapi_logis 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 tofastapi.endpointthroughapi.log_collection.mixin. On a database wherefastapi_logis not installed that field does not exist, so the access raised anAttributeErrorand broke every fastapi endpoint of that database.How to reproduce
Two databases in the same instance:
fastapi_loginstalledfastapiinstalled (nofastapi_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 (
AttributeErroronlog_requests), even though DB B never installedfastapi_log.Fix
Guard the field access with
"log_requests" in fastapi_endpoint._fieldsso logging only happens when the module is actually installed on the request's database; otherwise fall back to the base dispatch.