|
|
|
|
|
by cle
615 days ago
|
|
Dicts can be a problem, but this particular example isn't that great, like in this diagram from the article: External API <--dict--> Ser/De <--model--> Business Logic
Life's all great until "External API" adds a field that your model doesn't know about, it gets dropped when you deserialize it, and then when you send it back (or around somewhere else) it's missing a field.There's config for this in Pydantic, but it's not the default, and isn't for most ser/de frameworks (TypeScript is a notable exception here). Closed enums have a similar tradeoff. |
|
Dropping unknown/unused fields makes sense in 99% of cases.