Skip to content

computed_field with MissingType in return type: PydanticSerializationError: Unable to serialize unknown type: <MissingType>  #28

Open
@thibaut-lo

Description

@thibaut-lo

Hi - this is a very nice lib! Just reporting something I saw

from pydantic_partials import PartialModel, MissingType, Missing

from pydantic import computed_field

class Test(PartialModel):
    a: int

    @computed_field
    @property
    def b(self) -> int | MissingType:
          if a < 2:
              return Missing
          return a

t = Test(a=1)
t.model_dump_json()

raises

.local/lib/python3.11/site-packages/pydantic/main.py", line 415, in model_dump_json
    return self.__pydantic_serializer__.to_json(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'pydantic_partials.sentinels.MissingType'>

Instead, I would expect it to drop the computed_fields.

This is nit.

Versions

pydantic-partials: 1.1.0
pydantic: 2.8.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions