diff --git a/fastapi/dependencies.py b/fastapi/dependencies.py index 47b133285..1a7e299a8 100644 --- a/fastapi/dependencies.py +++ b/fastapi/dependencies.py @@ -1,7 +1,7 @@ # Copyright 2022 ACSONE SA/NV # License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL). -from typing import TYPE_CHECKING, Annotated +from typing import Annotated from odoo.api import Environment from odoo.exceptions import AccessDenied @@ -13,11 +13,9 @@ from fastapi.security import HTTPBasic, HTTPBasicCredentials from .context import odoo_env_ctx +from .models.fastapi_endpoint import FastapiEndpoint from .schemas import Paging -if TYPE_CHECKING: - from .models.fastapi_endpoint import FastapiEndpoint - def company_id() -> int | None: """This method may be overriden by the FastAPI app to set the allowed company diff --git a/fastapi/models/fastapi_endpoint.py b/fastapi/models/fastapi_endpoint.py index 27750f8cc..6f2d2e893 100644 --- a/fastapi/models/fastapi_endpoint.py +++ b/fastapi/models/fastapi_endpoint.py @@ -14,7 +14,6 @@ from fastapi import APIRouter, Depends, FastAPI -from .. import dependencies from ..middleware import ASGIMiddleware _logger = logging.getLogger(__name__) @@ -309,9 +308,12 @@ def _get_app(self) -> FastAPI: return app def _get_app_dependencies_overrides(self) -> dict[Callable, Callable]: + # Import here to avoid circular import while waiting for lazy imports + from ..dependencies import company_id, fastapi_endpoint_id + return { - dependencies.fastapi_endpoint_id: partial(lambda a: a, self.id), - dependencies.company_id: partial(lambda a: a, self.company_id.id), + fastapi_endpoint_id: partial(lambda a: a, self.id), + company_id: partial(lambda a: a, self.company_id.id), } def _prepare_fastapi_app_params(self) -> dict[str, Any]: @@ -336,4 +338,7 @@ def _get_fastapi_app_middlewares(self) -> list[Middleware]: def _get_fastapi_app_dependencies(self) -> list[Depends]: """Return the dependencies to use for the fastapi app.""" - return [Depends(dependencies.accept_language)] + # Import here to avoid circular import too + from ..dependencies import accept_language + + return [Depends(accept_language)]