Skip to content

python: pydantic validators are incompatible with betterproto Message #543

@jku

Description

@jku

We have these validators in our classes:

@model_validator(mode="after")
def check_oneof(cls, values):
    return cls._validate_field_groups(values)

This does not seem to work because of how betterproto Messages are instantiated from json:

Bundle().from_json(data)

from_json() is an instance method so I believe the validator runs before from_json() and fails if there are any groups in the model:

 pydantic_core._pydantic_core.ValidationError: 1 validation error for Bundle
   Value error, Group content has no value; all fields are None [type=value_error, input_value=ArgsKwargs(()), input_type=ArgsKwargs]
     For further information visit https://errors.pydantic.dev/2.10/v/value_error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions