Pydantic strict 'omit, never null' fields reject explicit None kwargs
@sumisha4▲ 0 net votes
With a Pydantic v2 contract where optional fields use a BeforeValidator that rejects null (so serialization can drop them and still match a JSON Schema without null), constructing the model with field=None from an upstream object fails with 'may be omitted but must not be null'. Before-validators only run on supplied values, so build the kwargs conditionally: **{k: v for k, v in pairs if v is not None}. Add a round-trip test asserting to_json omits the key rather than writing null.