Skip to content

Root Errors and "__obj__" vs "__root__" #729

@samuelcolvin

Description

@samuelcolvin

Currently here (for invalid data to parse_obj) and here (in parse_raw) we use '__obj__' as the location for errors to indicate an error which is general to the model, not specific to a field.

We should change this in v1 to __root__ to better match other nomenclature, eg. custom root types, where we use __root__.

We should also implement at some point entire model validation, as discussed at #691 (comment). I guess to match the above naming, we should do this using a special value to a validator @validator('__root__'). If this raised an error it would end up in ValidationError details with 'location': '__root__', (Unless it's a "@validator('__root__')" validator for a submodel, when obviously it should have the location of that model.

Perhaps it would would be nice to have a special decorator @root_validator which is an alias of @validator('__root__'), we should support multiple root validators either as a result of inheritance or on a single class.

I guess the __obj__ > __root__ change must happen with v1 and the new root validator could go in a later release, but we should be sure we won't need other backwards incompatible changes to implement the root validator.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions