Skip to content

Commit 90555bd

Browse files
committed
fix: when setting values, Pydantic would ask this to serialize them if the type was not exactly what it expected.
This resulted in values being serialized to `Missing` when they should have not been.
1 parent 9c508d5 commit 90555bd

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pydantic_partials/sentinels.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,15 @@ def _validate(value: Any, info: core_schema.ValidationInfo) -> 'MissingType':
3939
def _serialize(value: Any) -> 'MissingType':
4040
# Keeps the associated attribute 'deleted/omitted' from model.
4141
# raise PydanticOmit()
42-
# return 'a'
43-
return Missing
42+
43+
# Return same value we got, when requested to try and serialize real data it's not 'Missing',
44+
# and if it is, that means `Value` is `Missing` and we are fine to return that also.
45+
# I would love to rase a `raise PydanticOmit()` if `value` is `Missing`, but that does not currently work
46+
# for Pydantic, so I just return the `Missing` unchanged for now.
47+
# If there is a serialization error later on about how Pydantic can't turn `Missing` into a `Json`
48+
# then we can debug the situation
49+
# (right now PartialModel should delete any attributes that are set to `Missing` to work around this limitation)
50+
return value
4451

4552

4653
Missing = MissingType()

0 commit comments

Comments
 (0)