Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uncovered case in validator->field_validator #138

Open
anilbey opened this issue Nov 30, 2023 · 0 comments
Open

uncovered case in validator->field_validator #138

anilbey opened this issue Nov 30, 2023 · 0 comments

Comments

@anilbey
Copy link

anilbey commented Nov 30, 2023

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant