Skip to content

Commit 5dcbfd3

Browse files
committed
Add depreciation warning for Pydantic < 2
1 parent cbd5b48 commit 5dcbfd3

File tree

6 files changed

+94
-0
lines changed

6 files changed

+94
-0
lines changed

meilisearch_python_sdk/_client.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from datetime import datetime, timezone
55
from ssl import SSLContext
66
from types import TracebackType
7+
from warnings import warn
78

89
import jwt
910
from httpx import AsyncClient as HttpxAsyncClient
@@ -441,6 +442,10 @@ async def create_key(self, key: KeyCreate) -> Key:
441442
"keys", json.loads(key.model_dump_json(by_alias=True))
442443
) # type: ignore[attr-defined]
443444
else: # pragma: no cover
445+
warn(
446+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
447+
DeprecationWarning,
448+
)
444449
response = await self._http_requests.post("keys", json.loads(key.json(by_alias=True))) # type: ignore[attr-defined]
445450

446451
return Key(**response.json())
@@ -592,6 +597,10 @@ async def multi_search(self, queries: list[SearchParams]) -> list[SearchResultsW
592597
body={"queries": [x.model_dump(by_alias=True) for x in queries]}, # type: ignore[attr-defined]
593598
)
594599
else: # pragma: no cover
600+
warn(
601+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
602+
DeprecationWarning,
603+
)
595604
response = await self._http_requests.post(
596605
url,
597606
body={"queries": [x.dict(by_alias=True) for x in queries]}, # type: ignore[attr-defined]
@@ -1267,6 +1276,10 @@ def create_key(self, key: KeyCreate) -> Key:
12671276
"keys", json.loads(key.model_dump_json(by_alias=True))
12681277
) # type: ignore[attr-defined]
12691278
else: # pragma: no cover
1279+
warn(
1280+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
1281+
DeprecationWarning,
1282+
)
12701283
response = self._http_requests.post("keys", json.loads(key.json(by_alias=True))) # type: ignore[attr-defined]
12711284

12721285
return Key(**response.json())
@@ -1418,6 +1431,10 @@ def multi_search(self, queries: list[SearchParams]) -> list[SearchResultsWithUID
14181431
body={"queries": [x.model_dump(by_alias=True) for x in queries]}, # type: ignore[attr-defined]
14191432
)
14201433
else: # pragma: no cover
1434+
warn(
1435+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
1436+
DeprecationWarning,
1437+
)
14211438
response = self._http_requests.post(
14221439
url,
14231440
body={"queries": [x.dict(by_alias=True) for x in queries]}, # type: ignore[attr-defined]
@@ -1807,6 +1824,10 @@ def _build_update_key_payload(key: KeyUpdate) -> JsonDict:
18071824
if v is not None and k != "key"
18081825
}
18091826
else: # pragma: no cover
1827+
warn(
1828+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
1829+
DeprecationWarning,
1830+
)
18101831
return { # type: ignore[attr-defined]
18111832
k: v
18121833
for k, v in json.loads(key.json(by_alias=True)).items()

meilisearch_python_sdk/index.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pathlib import Path
99
from typing import Any, Generator
1010
from urllib.parse import urlencode
11+
from warnings import warn
1112

1213
import aiofiles
1314
from httpx import AsyncClient, Client
@@ -1728,6 +1729,10 @@ async def update_settings(self, body: MeilisearchSettings) -> TaskInfo:
17281729
if is_pydantic_2():
17291730
body_dict = {k: v for k, v in body.model_dump(by_alias=True).items() if v is not None} # type: ignore[attr-defined]
17301731
else: # pragma: no cover
1732+
warn(
1733+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
1734+
DeprecationWarning,
1735+
)
17311736
body_dict = {k: v for k, v in body.dict(by_alias=True).items() if v is not None} # type: ignore[attr-defined]
17321737

17331738
response = await self._http_requests.patch(self._settings_url, body_dict)
@@ -2428,6 +2433,10 @@ async def update_typo_tolerance(self, typo_tolerance: TypoTolerance) -> TaskInfo
24282433
f"{self._settings_url}/typo-tolerance", typo_tolerance.model_dump(by_alias=True)
24292434
) # type: ignore[attr-defined]
24302435
else: # pragma: no cover
2436+
warn(
2437+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
2438+
DeprecationWarning,
2439+
)
24312440
response = await self._http_requests.patch(
24322441
f"{self._settings_url}/typo-tolerance", typo_tolerance.dict(by_alias=True)
24332442
) # type: ignore[attr-defined]
@@ -2508,6 +2517,10 @@ async def update_faceting(self, faceting: Faceting) -> TaskInfo:
25082517
f"{self._settings_url}/faceting", faceting.model_dump(by_alias=True)
25092518
) # type: ignore[attr-defined]
25102519
else: # pragma: no cover
2520+
warn(
2521+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
2522+
DeprecationWarning,
2523+
)
25112524
response = await self._http_requests.patch(
25122525
f"{self._settings_url}/faceting", faceting.dict(by_alias=True)
25132526
) # type: ignore[attr-defined]
@@ -2589,6 +2602,10 @@ async def update_pagination(self, settings: Pagination) -> TaskInfo:
25892602
f"{self._settings_url}/pagination", settings.model_dump(by_alias=True)
25902603
) # type: ignore[attr-defined]
25912604
else: # pragma: no cover
2605+
warn(
2606+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
2607+
DeprecationWarning,
2608+
)
25922609
response = await self._http_requests.patch(
25932610
f"{self._settings_url}/pagination", settings.dict(by_alias=True)
25942611
) # type: ignore[attr-defined]
@@ -4367,6 +4384,10 @@ def update_settings(self, body: MeilisearchSettings) -> TaskInfo:
43674384
if is_pydantic_2():
43684385
body_dict = {k: v for k, v in body.model_dump(by_alias=True).items() if v is not None} # type: ignore[attr-defined]
43694386
else: # pragma: no cover
4387+
warn(
4388+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
4389+
DeprecationWarning,
4390+
)
43704391
body_dict = {k: v for k, v in body.dict(by_alias=True).items() if v is not None} # type: ignore[attr-defined]
43714392

43724393
response = self._http_requests.patch(self._settings_url, body_dict)
@@ -5061,6 +5082,10 @@ def update_typo_tolerance(self, typo_tolerance: TypoTolerance) -> TaskInfo:
50615082
f"{self._settings_url}/typo-tolerance", typo_tolerance.model_dump(by_alias=True)
50625083
) # type: ignore[attr-defined]
50635084
else: # pragma: no cover
5085+
warn(
5086+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
5087+
DeprecationWarning,
5088+
)
50645089
response = self._http_requests.patch(
50655090
f"{self._settings_url}/typo-tolerance", typo_tolerance.dict(by_alias=True)
50665091
) # type: ignore[attr-defined]
@@ -5141,6 +5166,10 @@ def update_faceting(self, faceting: Faceting) -> TaskInfo:
51415166
f"{self._settings_url}/faceting", faceting.model_dump(by_alias=True)
51425167
) # type: ignore[attr-defined]
51435168
else: # pragma: no cover
5169+
warn(
5170+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
5171+
DeprecationWarning,
5172+
)
51445173
response = self._http_requests.patch(
51455174
f"{self._settings_url}/faceting", faceting.dict(by_alias=True)
51465175
) # type: ignore[attr-defined]
@@ -5222,6 +5251,10 @@ def update_pagination(self, settings: Pagination) -> TaskInfo:
52225251
f"{self._settings_url}/pagination", settings.model_dump(by_alias=True)
52235252
) # type: ignore[attr-defined]
52245253
else: # pragma: no cover
5254+
warn(
5255+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
5256+
DeprecationWarning,
5257+
)
52255258
response = self._http_requests.patch(
52265259
f"{self._settings_url}/pagination", settings.dict(by_alias=True)
52275260
) # type: ignore[attr-defined]

meilisearch_python_sdk/models/client.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import datetime
22
from typing import Dict, List, Optional, Union
3+
from warnings import warn
34

45
import pydantic
56
from camel_converter.pydantic_base import CamelBase
@@ -21,6 +22,10 @@ def validate_last_update(cls, v: str) -> Union[datetime, None]:
2122
return iso_to_date_time(v)
2223

2324
else: # pragma: no cover
25+
warn(
26+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
27+
DeprecationWarning,
28+
)
2429

2530
@pydantic.validator("last_update", pre=True)
2631
@classmethod
@@ -45,6 +50,10 @@ def validate_expires_at(cls, v: str) -> Union[datetime, None]:
4550
return iso_to_date_time(v)
4651

4752
else: # pragma: no cover
53+
warn(
54+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
55+
DeprecationWarning,
56+
)
4857

4958
@pydantic.validator("expires_at", pre=True)
5059
@classmethod
@@ -86,6 +95,10 @@ def validate_updated_at(cls, v: str) -> Union[datetime, None]:
8695
return iso_to_date_time(v)
8796

8897
else: # pragma: no cover
98+
warn(
99+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
100+
DeprecationWarning,
101+
)
89102

90103
@pydantic.validator("created_at", pre=True)
91104
@classmethod
@@ -114,6 +127,10 @@ class KeyCreate(CamelBase):
114127
model_config = pydantic.ConfigDict(ser_json_timedelta="iso8601") # type: ignore[typeddict-unknown-key]
115128

116129
else: # pragma: no cover
130+
warn(
131+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
132+
DeprecationWarning,
133+
)
117134

118135
class Config:
119136
json_encoders = {
@@ -139,6 +156,10 @@ class KeyUpdate(CamelBase):
139156
model_config = pydantic.ConfigDict(ser_json_timedelta="iso8601") # type: ignore[typeddict-unknown-key]
140157

141158
else: # pragma: no cover
159+
warn(
160+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
161+
DeprecationWarning,
162+
)
142163

143164
class Config:
144165
json_encoders = {

meilisearch_python_sdk/models/index.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import datetime
22
from typing import Dict, Optional
3+
from warnings import warn
34

45
import pydantic
56
from camel_converter.pydantic_base import CamelBase
@@ -39,6 +40,10 @@ def validate_updated_at(cls, v: str) -> datetime:
3940
return converted
4041

4142
else: # pragma: no cover
43+
warn(
44+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
45+
DeprecationWarning,
46+
)
4247

4348
@pydantic.validator("created_at", pre=True)
4449
@classmethod

meilisearch_python_sdk/models/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Dict, List, Optional
2+
from warnings import warn
23

34
import pydantic
45
from camel_converter.pydantic_base import CamelBase
@@ -38,6 +39,10 @@ def validate_facet_order(cls, v: Optional[Dict[str, str]]) -> Optional[Dict[str,
3839
return v
3940

4041
else: # pragma: no cover
42+
warn(
43+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
44+
DeprecationWarning,
45+
)
4146

4247
@pydantic.validator("sort_facet_values_by") # type: ignore[attr-defined]
4348
@classmethod

meilisearch_python_sdk/models/task.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import datetime
22
from typing import List, Optional, Union
3+
from warnings import warn
34

45
import pydantic
56
from camel_converter.pydantic_base import CamelBase
@@ -48,6 +49,10 @@ def validate_finished_at(cls, v: str) -> Union[datetime, None]:
4849
return iso_to_date_time(v)
4950

5051
else: # pragma: no cover
52+
warn(
53+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
54+
DeprecationWarning,
55+
)
5156

5257
@pydantic.validator("enqueued_at", pre=True)
5358
@classmethod
@@ -98,6 +103,10 @@ def validate_enqueued_at(cls, v: str) -> datetime:
98103
return converted
99104

100105
else: # pragma: no cover
106+
warn(
107+
"The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
108+
DeprecationWarning,
109+
)
101110

102111
@pydantic.validator("enqueued_at", pre=True)
103112
@classmethod

0 commit comments

Comments
 (0)