44import warnings
55from typing import Any , Awaitable , Callable , Final
66
7+ from common_library .pydantic_networks_extension import AnyHttpUrlLegacy
78from fastapi import FastAPI , status
89from httpx import AsyncClient , HTTPError
9- from pydantic import AnyHttpUrl , PositiveFloat , TypeAdapter
10+ from pydantic import PositiveFloat , TypeAdapter
1011from tenacity import RetryCallState
1112from tenacity .asyncio import AsyncRetrying
1213from tenacity .retry import retry_if_exception_type
2324
2425DEFAULT_HTTP_REQUESTS_TIMEOUT : Final [PositiveFloat ] = 15
2526
26- _ANY_HTTP_URL_ADAPTER : TypeAdapter [AnyHttpUrl ] = TypeAdapter (AnyHttpUrl )
27+ _ANY_HTTP_URL_LEGACY_ADAPTER : TypeAdapter [AnyHttpUrlLegacy ] = TypeAdapter (AnyHttpUrlLegacy )
2728
2829logger = logging .getLogger (__name__ )
2930
@@ -115,7 +116,7 @@ class Client:
115116 status, result and/or cancel of a long running task.
116117 """
117118
118- def __init__ (self , app : FastAPI , async_client : AsyncClient , base_url : AnyHttpUrl ):
119+ def __init__ (self , app : FastAPI , async_client : AsyncClient , base_url : str ):
119120 """
120121 `app`: used byt the `Client` to recover the `ClientConfiguration`
121122 `async_client`: an AsyncClient instance used by `Client`
@@ -130,8 +131,8 @@ def _client_configuration(self) -> ClientConfiguration:
130131 output : ClientConfiguration = self .app .state .long_running_client_configuration
131132 return output
132133
133- def _get_url (self , path : str ) -> AnyHttpUrl :
134- return _ANY_HTTP_URL_ADAPTER .validate_python (
134+ def _get_url (self , path : str ) -> str :
135+ return _ANY_HTTP_URL_LEGACY_ADAPTER .validate_python (
135136 f"{ self ._base_url } { self ._client_configuration .router_prefix } { path } " ,
136137 )
137138
@@ -141,7 +142,7 @@ async def get_task_status(
141142 ) -> TaskStatus :
142143 timeout = timeout or self ._client_configuration .default_timeout
143144 result = await self ._async_client .get (
144- str ( self ._get_url (f"/task/{ task_id } " ) ),
145+ self ._get_url (f"/task/{ task_id } " ),
145146 timeout = timeout ,
146147 )
147148 if result .status_code != status .HTTP_200_OK :
@@ -160,7 +161,7 @@ async def get_task_result(
160161 ) -> Any | None :
161162 timeout = timeout or self ._client_configuration .default_timeout
162163 result = await self ._async_client .get (
163- str ( self ._get_url (f"/task/{ task_id } /result" ) ),
164+ self ._get_url (f"/task/{ task_id } /result" ),
164165 timeout = timeout ,
165166 )
166167 if result .status_code != status .HTTP_200_OK :
@@ -182,7 +183,7 @@ async def cancel_and_delete_task(
182183 ) -> None :
183184 timeout = timeout or self ._client_configuration .default_timeout
184185 result = await self ._async_client .delete (
185- str ( self ._get_url (f"/task/{ task_id } " ) ),
186+ self ._get_url (f"/task/{ task_id } " ),
186187 timeout = timeout ,
187188 )
188189
0 commit comments