Skip to content
Open
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
18 changes: 7 additions & 11 deletions qdrant_client/http/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from urllib.parse import urljoin

from httpx import AsyncClient, Client, Request, Response
from pydantic import ValidationError
from pydantic import TypeAdapter, ValidationError
from qdrant_client.common.client_exceptions import ResourceExhaustedResponse
from qdrant_client.http.api.aliases_api import AsyncAliasesApi, SyncAliasesApi
from qdrant_client.http.api.beta_api import AsyncBetaApi, SyncBetaApi
Expand Down Expand Up @@ -124,7 +124,7 @@ def send(self, request: Request, type_: Type[T]) -> T:

if response.status_code in [200, 201, 202]:
try:
return parse_as_type(response.json(), type_)
return parse_as_type(response.content, type_)
except ValidationError as e:
raise ResponseHandlingException(e)
raise UnexpectedResponse.for_response(response)
Expand Down Expand Up @@ -213,7 +213,7 @@ async def send(self, request: Request, type_: Type[T]) -> T:

if response.status_code in [200, 201, 202]:
try:
return parse_as_type(response.json(), type_)
return parse_as_type(response.content, type_)
except ValidationError as e:
raise ResponseHandlingException(e)
raise UnexpectedResponse.for_response(response)
Expand Down Expand Up @@ -251,13 +251,9 @@ def __call__(self, request: Request, call_next: Send) -> Response:


@lru_cache(maxsize=None)
def _get_parsing_type(type_: Any, source: str) -> Any:
from pydantic.main import create_model
def _wrap_in_pydantic_model(type_: T) -> TypeAdapter[T]:
return TypeAdapter(type_)

type_name = getattr(type_, "__name__", str(type_))
return create_model(f"ParsingModel[{type_name}] (for {source})", obj=(type_, ...))


def parse_as_type(obj: Any, type_: Type[T]) -> T:
model_type = _get_parsing_type(type_, source=parse_as_type.__name__)
return model_type(obj=obj).obj
def parse_as_type(data: bytes, type_: Type[T]) -> T:
return _wrap_in_pydantic_model(type_).validate_json(data)