fix: use correct model validator signature#586
Conversation
|
Confirmed And fails with these: Error: I am a little confused at how it's working with pydantic 2.11 because looking at the docs, 2.11 and 2.12 have the same signature for model after validators. https://docs.pydantic.dev/2.11/concepts/validators/#model-validators class UserModel(BaseModel):
username: str
password: str
password_repeat: str
@model_validator(mode='after')
def check_passwords_match(self) -> Self:
if self.password != self.password_repeat:
raise ValueError('Passwords do not match')
return selfhttps://docs.pydantic.dev/2.12/concepts/validators/#model-validators class UserModel(BaseModel):
username: str
password: str
password_repeat: str
@model_validator(mode='after')
def check_passwords_match(self) -> Self:
if self.password != self.password_repeat:
raise ValueError('Passwords do not match')
return self |
|
@theferrit32 what intrigues me is that the changelog makes it seem as though v2.12 will now raise some kind of validation error, and that's not what's happening to us -- rather, we're just getting some unexpected values and then the failure happens within the validator function |
|
@jsstevenson If I add this assert at the bottom in your branch using pydantic 2.12 def test_mappable_concept():
"""Test the MappableConcept model validator"""
# Does not provide required fields
with pytest.raises(
ValueError, match="One of `name` or `primaryCoding` must be provided."
):
core_models.MappableConcept(conceptType="test")
# Valid models
assert core_models.MappableConcept(name="Primary Label")
assert core_models.MappableConcept(
primaryCoding=core_models.Coding(
code="HGNC:1097",
system="https://www.genenames.org/data/gene-symbol-report/#!/hgnc_id/",
)
)
assert core_models.MappableConcept(
primaryCoding=core_models.Coding(
# code="HGNC:1097",
system="https://www.genenames.org/data/gene-symbol-report/#!/hgnc_id/",
)
)I get Which I think is right? |
|
This So I guess we don't need to constrain pyproject.toml to |
We had previously been using an incorrect method signature that was apparently working, but in an undefined way, and pydantic v 2.12 "fixed" (broke, for us) this -- see "after model validators" https://pydantic.dev/articles/pydantic-v2-12-release)