Upgrade to Pydantic 2 or make Pydantic support optional?
I'm working a Starlette project that uses Pydantic v2. I'd be interested in trying out cacheme, but the conflicting Pydantic version requirements make it impossible. Two obvious options present themselves:
- Upgrade the Pydantic support to v2 (migration guide), or
- Make pydantic support optional (perhaps allow customization of
object_encoder/object_decoderon the Serialization classes, with the default being an identity function for accepting/returning primitive types.
Thank you for considering this.
@Yiling-J you have done a good job, nice lib, but sincerely we need to update it to pydantic v2 Please leave a comment below if you need help or contribution in migration
@eykd @aspatari Sorry for no replying because I miss the notification when this issue was opened (seems I didn't even receive it). I'm not very familiar with Pydantic and haven't been using Python recently. It would be greatly appreciated if you could help @aspatari. but if you're busy I can certainly take a look into it myself.
@eykd @aspatari After reading the Pydantic documentation a bit, I think it might be better to remove the serializer concept altogether and instead adding dumps and loads methods directly to the Node class:
- If the user hasn't overridden
dumpsandloads, and the Node object inherits from Pydantic BaseModel or is Pydantic dataclass, using Pydantic's built-in methods. - If the user hasn't overridden
dumpsandloads, and the Node object is a Python dataclass, Pydantic'sTypeAdaptercould be used. It requires a class as an input parameter, implementing these methods on Node resolves this. - If the user hasn't overridden
dumpsandloads, and the Node object is a arbitrary Python object, using pickle instead. - If the user has overridden
dumpsandloads, just use them.
Considering that cacheme isn't widely adopted (13 downloads last week), I think removing the serializer won't introduce any significant issues.