Skip to content

Conversation

@NeejWeej
Copy link
Collaborator

@NeejWeej NeejWeej commented Oct 7, 2025

According to this PR: pydantic/pydantic#11957

model_validators shouldn't be class methods.

Follows the example here:
https://github.com/pydantic/pydantic/blob/v2.12.0/tests/test_model_validator.py#L85

from the pydantic test suite to have a model validator that takes a ValidationInfo parameter

(as-of time of writing)

def test_model_validator_after() -> None:
    class Model(BaseModel):
        x: int
        y: int

        @model_validator(mode='after')
        def val_model(self, info: ValidationInfo) -> Model:
            assert not info.context
            self.x += 1
            self.y += 1
            return self

    assert Model(x=1, y=2).model_dump() == {'x': 2, 'y': 3}
    assert Model.model_validate(Model(x=1, y=2)).model_dump() == {'x': 3, 'y': 4}

@NeejWeej NeejWeej merged commit 3b7b513 into main Oct 7, 2025
27 checks passed
@NeejWeej NeejWeej deleted the nk/pydantic_2_12_fix branch October 7, 2025 19:58
AdamGlustein pushed a commit that referenced this pull request Oct 8, 2025
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

Successfully merging this pull request may close these issues.

3 participants