Skip to content

Commit 21ce578

Browse files
committed
Fxing circular imports causing 'FastapiEndpoint' not recognized
1 parent 2536013 commit 21ce578

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

fastapi/models/fastapi_endpoint_demo.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@
1111
from fastapi import APIRouter, Depends, HTTPException, status
1212
from fastapi.security import APIKeyHeader
1313

14+
1415
from ..dependencies import (
1516
authenticated_partner_from_basic_auth_user,
1617
authenticated_partner_impl,
1718
odoo_env,
1819
)
19-
from ..routers import demo_router, demo_router_doc
20+
21+
# Add imports for TYPE_CHECKING
22+
from typing import TYPE_CHECKING
23+
if TYPE_CHECKING:
24+
from ..routers import demo_router, demo_router_doc
2025

2126

2227
class FastapiEndpoint(models.Model):
@@ -32,6 +37,8 @@ class FastapiEndpoint(models.Model):
3237

3338
def _get_fastapi_routers(self) -> list[APIRouter]:
3439
if self.app == "demo":
40+
# Import here to avoid circular import
41+
from ..routers import demo_router
3542
return [demo_router]
3643
return super()._get_fastapi_routers()
3744

@@ -73,6 +80,8 @@ def _get_app(self):
7380
def _prepare_fastapi_app_params(self) -> dict[str, Any]:
7481
params = super()._prepare_fastapi_app_params()
7582
if self.app == "demo":
83+
# Import here to avoid circular import
84+
from ..routers import demo_router_doc
7685
tags_metadata = params.get("openapi_tags", []) or []
7786
tags_metadata.append({"name": "demo", "description": demo_router_doc})
7887
params["openapi_tags"] = tags_metadata
@@ -101,4 +110,4 @@ def api_key_based_authenticated_partner_impl(
101110
raise HTTPException(
102111
status_code=status.HTTP_401_UNAUTHORIZED, detail="Incorrect API Key"
103112
)
104-
return partner
113+
return partner

fastapi/routers/demo_router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async def who_ami(
8383
dependencies=[Depends(authenticated_partner)],
8484
)
8585
async def endpoint_app_info(
86-
endpoint: Annotated[FastapiEndpoint, Depends(fastapi_endpoint)],
86+
endpoint: Annotated["FastapiEndpoint", Depends(fastapi_endpoint)],
8787
) -> DemoEndpointAppInfo:
8888
"""Returns the current endpoint configuration"""
8989
# This method show you how to get access to current endpoint configuration

0 commit comments

Comments
 (0)