Open alexdrydew opened 3 hours ago
Ops... githubkit has already added a custom validation function for the Unset type. This seems not working.
Hi, i just reproduce the example. To convert a model into a jsonable dict (json mode), you should use:
from githubkit.utils import UNSET
from githubkit.typing import Missing
from githubkit.compat import GitHubModel
class TestModel(GitHubModel):
a: Missing[bool] = UNSET
a = TestModel().model_dump(mode="json", exclude_unset=True)
TestModel.model_validate(a)
Since UNSET
is just a placeholder and should not be converted into string type (which is a valid data type), you need to turn on the exclude_unset
option.
Oh, right, that works. Thank you! Just a suggestion: maybe it would be handy to use a custom serializer not to include UNSET
by default when serializing models?
adding a serializer will make the pydantic v1/v2 compat layer too complex. i could add a note to the documentation.
Pydantic V2 does not allow validating Literal of plain enum by enum values:
raises
Relevant pydantic issue: https://github.com/pydantic/pydantic/issues/8708
Pydantic and python version: