This repository was archived by the owner on Sep 8, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +21
-6
lines changed
Expand file tree Collapse file tree 3 files changed +21
-6
lines changed Original file line number Diff line number Diff line change 2020)
2121from ..exceptions import APIError , APIErrorFromJSON , generate_default_error_message
2222from ..types import ReturnMethod
23- from ..utils import get_origin_and_cast
23+ from ..utils import get_origin_and_cast , model_validate_json
2424
2525_ReturnT = TypeVar ("_ReturnT" )
2626
@@ -74,7 +74,7 @@ async def execute(self) -> APIResponse[_ReturnT]:
7474 return body
7575 return APIResponse [_ReturnT ].from_http_request_response (r )
7676 else :
77- json_obj = APIErrorFromJSON . model_validate_json (r .content )
77+ json_obj = model_validate_json (APIErrorFromJSON , r .content )
7878 raise APIError (dict (json_obj ))
7979 except ValidationError as e :
8080 raise APIError (generate_default_error_message (r ))
@@ -122,7 +122,7 @@ async def execute(self) -> SingleAPIResponse[_ReturnT]:
122122 ): # Response.ok from JS (https://developer.mozilla.org/en-US/docs/Web/API/Response/ok)
123123 return SingleAPIResponse [_ReturnT ].from_http_request_response (r )
124124 else :
125- json_obj = APIErrorFromJSON . model_validate_json (r .content )
125+ json_obj = model_validate_json (APIErrorFromJSON , r .content )
126126 raise APIError (dict (json_obj ))
127127 except ValidationError as e :
128128 raise APIError (generate_default_error_message (r ))
Original file line number Diff line number Diff line change 2020)
2121from ..exceptions import APIError , APIErrorFromJSON , generate_default_error_message
2222from ..types import ReturnMethod
23- from ..utils import get_origin_and_cast
23+ from ..utils import get_origin_and_cast , model_validate_json
2424
2525_ReturnT = TypeVar ("_ReturnT" )
2626
@@ -74,7 +74,7 @@ def execute(self) -> APIResponse[_ReturnT]:
7474 return body
7575 return APIResponse [_ReturnT ].from_http_request_response (r )
7676 else :
77- json_obj = APIErrorFromJSON . model_validate_json (r .content )
77+ json_obj = model_validate_json (APIErrorFromJSON , r .content )
7878 raise APIError (dict (json_obj ))
7979 except ValidationError as e :
8080 raise APIError (generate_default_error_message (r ))
@@ -122,7 +122,7 @@ def execute(self) -> SingleAPIResponse[_ReturnT]:
122122 ): # Response.ok from JS (https://developer.mozilla.org/en-US/docs/Web/API/Response/ok)
123123 return SingleAPIResponse [_ReturnT ].from_http_request_response (r )
124124 else :
125- json_obj = APIErrorFromJSON . model_validate_json (r .content )
125+ json_obj = model_validate_json (APIErrorFromJSON , r .content )
126126 raise APIError (dict (json_obj ))
127127 except ValidationError as e :
128128 raise APIError (generate_default_error_message (r ))
Original file line number Diff line number Diff line change 77from deprecation import deprecated
88from httpx import AsyncClient # noqa: F401
99from httpx import Client as BaseClient # noqa: F401
10+ from pydantic import BaseModel
1011
1112from .version import __version__
1213
@@ -81,3 +82,17 @@ def is_valid_jwt(value: str) -> bool:
8182 return False
8283
8384 return True
85+
86+
87+ TBaseModel = TypeVar ("TBaseModel" , bound = BaseModel )
88+
89+
90+ def model_validate_json (model : Type [TBaseModel ], contents ) -> TBaseModel :
91+ """Compatibility layer between pydantic 1 and 2 for parsing an instance
92+ of a BaseModel from varied"""
93+ try :
94+ # pydantic > 2
95+ return model .model_validate_json (contents )
96+ except AttributeError :
97+ # pydantic < 2
98+ return model .parse_raw (contents )
You can’t perform that action at this time.
0 commit comments