Skip to content

Optimize non-discriminated unions based on incompatible schemas #434

Open
@adriangb

Description

@adriangb

It would be nice if Pydantic automatically figured out the path of least cost to determine which item in a union we should pursue. Essentially we'd want to figure out the divergent points between two schemas and check those via a depth-first sort of validation instead of a breadth-first type validation that we currently do. Some obvious cases are:

  • A literal field that diverges
  • Fields that are only present in one model or some of the models
  • Fields that have totally incompatible types

It does get tricky e.g. with a combination of these.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions