Skip to content

Commit b9d9887

Browse files
authored
fix: use correct model validator signature (#586)
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)
1 parent 4f45c5b commit b9d9887

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ dependencies = [
4141
"requests",
4242
"canonicaljson",
4343
"setuptools>=78.1.0", # TODO remove this pin caused by HGVS issue
44+
"typing-extensions",
4445
]
4546

4647
[project.optional-dependencies]

src/ga4gh/core/models.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
StringConstraints,
1515
model_validator,
1616
)
17+
from typing_extensions import Self
1718

1819
from ga4gh.core.identifiers import GA4GH_IR_REGEXP
1920

@@ -216,12 +217,12 @@ class MappableConcept(Element, BaseModelForbidExtra):
216217
)
217218

218219
@model_validator(mode="after")
219-
def require_name_or_primary_coding(cls, v): # noqa: ANN001 N805 ANN201
220+
def require_name_or_primary_coding(self) -> Self:
220221
"""Ensure that ``name`` or ``primaryCoding`` is provided"""
221-
if v.primaryCoding is None and v.name is None:
222+
if self.primaryCoding is None and self.name is None:
222223
err_msg = "One of `name` or `primaryCoding` must be provided."
223224
raise ValueError(err_msg)
224-
return v
225+
return self
225226

226227

227228
Element.model_rebuild()

0 commit comments

Comments
 (0)