Skip to content

Support Sentinel types in pydantic models #3207

@MartinBernstorff

Description

@MartinBernstorff

Describe the Bug

import pydantic
from pydantic.experimental.missing_sentinel import MISSING

class UpdateUserPayload(pydantic.BaseModel):
    phone_number: str | MISSING = MISSING 
    # Errors with "Expected a type form, got instance of `type[str] | UnionType`". Should not error.

This is an experimental feature, but required if you have a PATCH model and the generated schema shouldn't erroneously indicate that the value is nullable.

https://pydantic.dev/docs/validation/latest/concepts/experimental/#missing-sentinel

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    pydanticIssues related to support for Pydantic
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions