cacheme icon indicating copy to clipboard operation
cacheme copied to clipboard

Upgrade to Pydantic 2 or make Pydantic support optional?

Open eykd opened this issue 1 year ago • 3 comments

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:

  1. Upgrade the Pydantic support to v2 (migration guide), or
  2. Make pydantic support optional (perhaps allow customization of object_encoder/object_decoder on the Serialization classes, with the default being an identity function for accepting/returning primitive types.

Thank you for considering this.

eykd avatar Jan 23 '24 00:01 eykd

@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

aspatari avatar Jul 31 '24 09:07 aspatari

@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.

Yiling-J avatar Jul 31 '24 09:07 Yiling-J

@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 dumps and loads, and the Node object inherits from Pydantic BaseModel or is Pydantic dataclass, using Pydantic's built-in methods.
  • If the user hasn't overridden dumps and loads, and the Node object is a Python dataclass, Pydantic's TypeAdapter could be used. It requires a class as an input parameter, implementing these methods on Node resolves this.
  • If the user hasn't overridden dumps and loads, and the Node object is a arbitrary Python object, using pickle instead.
  • If the user has overridden dumps and loads, 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.

Yiling-J avatar Aug 02 '24 14:08 Yiling-J