Skip to content

Commit cd117b2

Browse files
sethbuffjmmenard
andauthored
Full Pydantic 2.0 Support + Bug Fixes (#691)
* remove pydantic v1 references * set validate_default=True * Remove unused imports * update models to specify when a model is final * fix knn setup * Update KNN test query * Update KNN results include score * remove use of alias for queries * fix lint issues * fix lint issues * fix annotations for python < 3.10 * fix annotations for python < 3.10 * fix issue where certain fields were unintentionally being indexed * remove vscode settings * dynamically set index based on other fields that require indexes * fix inheritance from indexed model * fix linting errors * change version to beta * make default a positional arg on Field * Include knn in model construction * add warning for auto indexing * use field info args without default to prevent overlapping values * update typing to support older python versions --------- Co-authored-by: jmmenard <[email protected]>
1 parent 277ed25 commit cd117b2

13 files changed

+500
-421
lines changed

aredis_om/_compat.py

-99
This file was deleted.

aredis_om/checks.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from functools import lru_cache
2-
from typing import List
32

43
from aredis_om.connections import get_redis_connection
54

aredis_om/model/encoders.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
from types import GeneratorType
3232
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
3333

34-
from .._compat import ENCODERS_BY_TYPE, BaseModel
34+
from pydantic import BaseModel
35+
from pydantic.deprecated.json import ENCODERS_BY_TYPE
36+
from pydantic_core import PydanticUndefined
3537

3638

3739
SetIntStr = Set[Union[int, str]]
@@ -72,7 +74,7 @@ def jsonable_encoder(
7274
encoder = getattr(obj.__config__, "json_encoders", {})
7375
if custom_encoder:
7476
encoder.update(custom_encoder)
75-
obj_dict = obj.dict(
77+
obj_dict = obj.model_dump(
7678
include=include, # type: ignore # in Pydantic
7779
exclude=exclude, # type: ignore # in Pydantic
7880
by_alias=by_alias,
@@ -106,6 +108,7 @@ def jsonable_encoder(
106108
or (not isinstance(key, str))
107109
or (not key.startswith("_sa"))
108110
)
111+
and value is not PydanticUndefined
109112
and (value is not None or not exclude_none)
110113
and ((include and key in include) or not exclude or key not in exclude)
111114
):

aredis_om/model/migrations/migrator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ async def detect_migrations(self):
131131

132132
stored_hash = await conn.get(hash_key)
133133
if isinstance(stored_hash, bytes):
134-
stored_hash = stored_hash.decode('utf-8')
134+
stored_hash = stored_hash.decode("utf-8")
135135

136136
schema_out_of_date = current_hash != stored_hash
137137

0 commit comments

Comments
 (0)