Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions fastapi/dependencies.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
13 changes: 9 additions & 4 deletions fastapi/models/fastapi_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from fastapi import APIRouter, Depends, FastAPI

from .. import dependencies
from ..middleware import ASGIMiddleware

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -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]:
Expand All @@ -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)]