Skip to content

uncovered case in validator->field_validator #138

Open
@anilbey

Description

@anilbey

Hello, moving from V1 to V2, this output gets created by bump-pydantic.

    # TODO[pydantic]: We couldn't refactor the `validator`, please replace it by `field_validator` manually.
    # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-validators for more information.
    @validator("decay_time")
    def decay_time_gt_rise_time(cls, v, values):
        if v <= values["rise_time"]:
            raise ValueError("decay_time must be greater than rise_time")
        return v

When this occurs, the values need to become values.data then all works fine. Maybe this refactoring can be added to the tool.

Before (V1)

    @validator("decay_time")
    def decay_time_gt_rise_time(cls, v, values):
        if v <= values["rise_time"]:
            raise ValueError("decay_time must be greater than rise_time")
        return v

After (V2)

    @field_validator("decay_time")
    @classmethod
    def decay_time_gt_rise_time(cls, v, values):
        if v <= values.data["rise_time"]:
            raise ValueError("decay_time must be greater than rise_time")
        return v

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