Skip to content

Commit 9757421

Browse files
authored
Merge pull request #559 from sanders41/pydantic2
Fix issue with Pydantic version check
2 parents 12afbfe + 1c72966 commit 9757421

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

meilisearch_python_async/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ async def create_key(self, key: KeyCreate) -> Key:
389389
"""
390390
# The json.loads(key.json()) is because Pydantic can't serialize a date in a Python dict,
391391
# but can when converting to a json string.
392-
if is_pydantic_2:
392+
if is_pydantic_2():
393393
response = await self._http_requests.post("keys", json.loads(key.model_dump_json(by_alias=True))) # type: ignore[attr-defined]
394394
else: # pragma: no cover
395395
response = await self._http_requests.post("keys", json.loads(key.json(by_alias=True))) # type: ignore[attr-defined]
@@ -499,7 +499,7 @@ async def update_key(self, key: KeyUpdate) -> Key:
499499
"""
500500
# The json.loads(key.json()) is because Pydantic can't serialize a date in a Python dict,
501501
# but can when converting to a json string.
502-
if is_pydantic_2:
502+
if is_pydantic_2():
503503
payload = { # type: ignore[attr-defined]
504504
k: v
505505
for k, v in json.loads(key.model_dump_json(by_alias=True)).items()
@@ -543,7 +543,7 @@ async def multi_search(self, queries: list[SearchParams]) -> list[SearchResultsW
543543
>>> search_results = await client.search(queries)
544544
"""
545545
url = "multi-search"
546-
if is_pydantic_2:
546+
if is_pydantic_2():
547547
response = await self._http_requests.post(
548548
url, body={"queries": [x.model_dump(by_alias=True) for x in queries]} # type: ignore[attr-defined]
549549
)

meilisearch_python_async/index.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,7 @@ async def update_settings(self, body: MeilisearchSettings) -> TaskInfo:
14781478
>>> index = client.index("movies")
14791479
>>> await index.update_settings(new_settings)
14801480
"""
1481-
if is_pydantic_2:
1481+
if is_pydantic_2():
14821482
body_dict = {k: v for k, v in body.model_dump(by_alias=True).items() if v is not None} # type: ignore[attr-defined]
14831483
else: # pragma: no cover
14841484
body_dict = {k: v for k, v in body.dict(by_alias=True).items() if v is not None} # type: ignore[attr-defined]
@@ -2189,7 +2189,7 @@ async def update_typo_tolerance(self, typo_tolerance: TypoTolerance) -> TaskInfo
21892189
"""
21902190
url = f"{self._settings_url}/typo-tolerance"
21912191

2192-
if is_pydantic_2:
2192+
if is_pydantic_2():
21932193
response = await self._http_requests.patch(url, typo_tolerance.model_dump(by_alias=True)) # type: ignore[attr-defined]
21942194
else: # pragma: no cover
21952195
response = await self._http_requests.patch(url, typo_tolerance.dict(by_alias=True)) # type: ignore[attr-defined]
@@ -2265,7 +2265,7 @@ async def update_faceting(self, faceting: Faceting) -> TaskInfo:
22652265
"""
22662266
url = f"{self._settings_url}/faceting"
22672267

2268-
if is_pydantic_2:
2268+
if is_pydantic_2():
22692269
response = await self._http_requests.patch(url, faceting.model_dump(by_alias=True)) # type: ignore[attr-defined]
22702270
else: # pragma: no cover
22712271
response = await self._http_requests.patch(url, faceting.dict(by_alias=True)) # type: ignore[attr-defined]
@@ -2342,7 +2342,7 @@ async def update_pagination(self, settings: Pagination) -> TaskInfo:
23422342
"""
23432343
url = f"{self._settings_url}/pagination"
23442344

2345-
if is_pydantic_2:
2345+
if is_pydantic_2():
23462346
response = await self._http_requests.patch(url, settings.model_dump(by_alias=True)) # type: ignore[attr-defined]
23472347
else: # pragma: no cover
23482348
response = await self._http_requests.patch(url, settings.dict(by_alias=True)) # type: ignore[attr-defined]

meilisearch_python_async/models/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ClientStats(CamelBase):
1313
last_update: Optional[datetime] = None
1414
indexes: Optional[Dict[str, IndexStats]] = None
1515

16-
if is_pydantic_2:
16+
if is_pydantic_2():
1717

1818
@pydantic.field_validator("last_update", mode="before") # type: ignore[attr-defined]
1919
@classmethod
@@ -36,7 +36,7 @@ class _KeyBase(CamelBase):
3636
indexes: List[str]
3737
expires_at: Optional[datetime] = None
3838

39-
if is_pydantic_2:
39+
if is_pydantic_2():
4040
model_config = pydantic.ConfigDict(ser_json_timedelta="iso8601") # type: ignore[typeddict-unknown-key]
4141

4242
@pydantic.field_validator("expires_at", mode="before") # type: ignore[attr-defined]
@@ -62,7 +62,7 @@ class Key(_KeyBase):
6262
created_at: datetime
6363
updated_at: Optional[datetime] = None
6464

65-
if is_pydantic_2:
65+
if is_pydantic_2():
6666

6767
@pydantic.field_validator("created_at", mode="before") # type: ignore[attr-defined]
6868
@classmethod
@@ -104,7 +104,7 @@ class KeyCreate(CamelBase):
104104
indexes: List[str]
105105
expires_at: Optional[datetime] = None
106106

107-
if is_pydantic_2:
107+
if is_pydantic_2():
108108
model_config = pydantic.ConfigDict(ser_json_timedelta="iso8601") # type: ignore[typeddict-unknown-key]
109109

110110
else: # pragma: no cover
@@ -123,7 +123,7 @@ class KeyUpdate(CamelBase):
123123
indexes: Optional[List[str]] = None
124124
expires_at: Optional[datetime] = None
125125

126-
if is_pydantic_2:
126+
if is_pydantic_2():
127127
model_config = pydantic.ConfigDict(ser_json_timedelta="iso8601") # type: ignore[typeddict-unknown-key]
128128

129129
else: # pragma: no cover

meilisearch_python_async/models/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class IndexInfo(IndexBase):
1616
created_at: datetime
1717
updated_at: datetime
1818

19-
if is_pydantic_2:
19+
if is_pydantic_2():
2020

2121
@pydantic.field_validator("created_at", mode="before") # type: ignore[attr-defined]
2222
@classmethod

meilisearch_python_async/models/task.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TaskStatus(TaskId):
2424
started_at: Optional[datetime]
2525
finished_at: Optional[datetime]
2626

27-
if is_pydantic_2:
27+
if is_pydantic_2():
2828

2929
@pydantic.field_validator("enqueued_at", mode="before") # type: ignore[attr-defined]
3030
@classmethod
@@ -76,7 +76,7 @@ class TaskInfo(CamelBase):
7676
task_type: Union[str, Dict[str, Any]] = Field(..., alias="type")
7777
enqueued_at: datetime
7878

79-
if is_pydantic_2:
79+
if is_pydantic_2():
8080

8181
@pydantic.field_validator("enqueued_at", mode="before") # type: ignore[attr-defined]
8282
@classmethod

0 commit comments

Comments
 (0)