From 6a4a31ee884757ee26c669e03003f2c3cf83b1ce Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Wed, 11 Feb 2026 21:24:20 -0500 Subject: [PATCH 1/3] fix: handle case where constraint.relations=None --- src/ga4gh/cat_vrs/recipes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ga4gh/cat_vrs/recipes.py b/src/ga4gh/cat_vrs/recipes.py index 52374e7..bc3e62a 100644 --- a/src/ga4gh/cat_vrs/recipes.py +++ b/src/ga4gh/cat_vrs/recipes.py @@ -180,7 +180,8 @@ def validate_constraints(cls, v: list[Constraint]) -> list[Constraint]: ): def_loc_constr_found = True - for r in constraint.relations: + relations = constraint.relations or [] + for r in relations: if r.primaryCoding and ( r.primaryCoding.code.root == Relation.LIFTOVER_TO.value and r.primaryCoding.system From 09d709b006dc80f2428097c1ece89f36ce5b0d59 Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Thu, 12 Feb 2026 09:06:01 -0500 Subject: [PATCH 2/3] add test --- tests/validation/test_cat_vrs_models.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/validation/test_cat_vrs_models.py b/tests/validation/test_cat_vrs_models.py index 87c5e4a..416aa79 100644 --- a/tests/validation/test_cat_vrs_models.py +++ b/tests/validation/test_cat_vrs_models.py @@ -1,5 +1,6 @@ """Test Cat VRS Pydantic models""" +import re from copy import deepcopy import pytest @@ -366,7 +367,11 @@ def test_canonical_allele(defining_loc_constr, members_and_name): recipes.CanonicalAllele(**valid_params) -def test_categorical_cnv(members_and_name, defining_loc_constr, copy_change_constr): +def test_categorical_cnv( + members_and_name: dict, + defining_loc_constr: models.DefiningLocationConstraint, + copy_change_constr: models.CopyChangeConstraint, +): """Test the CategoricalCnv validator""" # Valid CategoricalCnv with CopyChangeConstraint valid_params = deepcopy(members_and_name) @@ -384,6 +389,22 @@ def test_categorical_cnv(members_and_name, defining_loc_constr, copy_change_cons ] assert recipes.CategoricalCnv(**valid_params) + # Invalid CategoricalCnv: relations unset on DLC + invalid_params = deepcopy(members_and_name) + invalid_dlc = deepcopy(defining_loc_constr) + invalid_dlc.relations = None + invalid_params["constraints"] = [ + models.Constraint(root=invalid_dlc), + models.Constraint(root=models.CopyCountConstraint(copies=[1, 2])), + ] + with pytest.raises( + ValueError, + match=re.escape( + "1 validation error for CategoricalCnv\nconstraints\n Value error, `DefiningLocationConstraint` found, but must contain at least one relation where `primaryCoding.code` is 'liftover_to' and `primaryCoding.system` is 'ga4gh-gks-term:allele-relation'. [type=value_error, input_value=[Constraint(root=Defining...es=Range(root=[1, 2])))], input_type=list]\n For further information visit https://errors.pydantic.dev/2.11/v/value_error" + ), + ): + recipes.CategoricalCnv(**invalid_params) + # Invalid CategoricalCnv: No DefiningLocationConstraint invalid_params = deepcopy(members_and_name) invalid_params["constraints"] = [ From 3b4493a68317c4482d7a076ed4521a3779fe5a99 Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Thu, 12 Feb 2026 09:17:32 -0500 Subject: [PATCH 3/3] does this work? --- tests/validation/test_cat_vrs_models.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/validation/test_cat_vrs_models.py b/tests/validation/test_cat_vrs_models.py index 416aa79..7b7f3e7 100644 --- a/tests/validation/test_cat_vrs_models.py +++ b/tests/validation/test_cat_vrs_models.py @@ -1,6 +1,5 @@ """Test Cat VRS Pydantic models""" -import re from copy import deepcopy import pytest @@ -399,9 +398,7 @@ def test_categorical_cnv( ] with pytest.raises( ValueError, - match=re.escape( - "1 validation error for CategoricalCnv\nconstraints\n Value error, `DefiningLocationConstraint` found, but must contain at least one relation where `primaryCoding.code` is 'liftover_to' and `primaryCoding.system` is 'ga4gh-gks-term:allele-relation'. [type=value_error, input_value=[Constraint(root=Defining...es=Range(root=[1, 2])))], input_type=list]\n For further information visit https://errors.pydantic.dev/2.11/v/value_error" - ), + match="`DefiningLocationConstraint` found, but must contain at least one relation where `primaryCoding.code` is 'liftover_to' and `primaryCoding.system` is 'ga4gh-gks-term:allele-relation'.", ): recipes.CategoricalCnv(**invalid_params)