msgspec icon indicating copy to clipboard operation
msgspec copied to clipboard

Set field if not provided based on value of another field

Open Ayehavgunne opened this issue 4 months ago • 2 comments

Description

Last I checked, this library didn't have the ability to set the value of a field that was not passed in for deserialization based on the value of another field that has already been validated. This is the one reason I am using Pydantic right now. It would be great if this was possible.

Or maybe I missed this somewhere?

Ayehavgunne avatar Sep 12 '25 23:09 Ayehavgunne

Oh, and the other thing is that the model is frozen

Ayehavgunne avatar Sep 17 '25 19:09 Ayehavgunne

I think you can do this with a __post_init__ function

edit: link https://jcristharif.com/msgspec/structs.html#post-init-processing

SZRabinowitz avatar Oct 06 '25 21:10 SZRabinowitz