Skip to content

Commit a28ea72

Browse files
committed
Debug a validator, modify a test and change the alembic version number.
1 parent 9f6abfa commit a28ea72

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

alembic/versions/0b29eefbe1dd_controlled_keyword_modification.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""controlled keyword modification
22
33
Revision ID: 0b29eefbe1dd
4-
Revises: af87c9953d2d
4+
Revises: 2b7a977e7e98
55
Create Date: 2025-08-07 15:45:43.241567
66
77
"""
@@ -11,7 +11,7 @@
1111

1212
# revision identifiers, used by Alembic.
1313
revision = '0b29eefbe1dd'
14-
down_revision = 'af87c9953d2d'
14+
down_revision = '2b7a977e7e98'
1515
branch_labels = None
1616
depends_on = None
1717

src/mavedb/view_models/keyword.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from typing import Optional
55

6-
from pydantic import field_validator
6+
from pydantic import field_validator, model_validator
77

88
from mavedb.lib.validation import keywords
99
from mavedb.view_models import record_type_validator, set_record_type
@@ -29,12 +29,11 @@ def validate_key(cls, v: str) -> str:
2929
keywords.validate_keyword(v)
3030
return v
3131

32-
@field_validator("code")
33-
def validate_code(cls, value, values):
34-
key = values.get("key")
35-
label = values.get("label")
36-
keywords.validate_code(key, label, value)
37-
return value
32+
@model_validator(mode="after")
33+
def validate_code(self):
34+
keywords.validate_code(self.key, self.label, self.code)
35+
return self
36+
3837

3938
# TODO#273: Un-commenting this block will require new experiments to contain a keyword on creation.
4039
# @field_validator("label")

tests/routers/test_experiments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def test_cannot_create_experiment_that_keyword_has_an_invalid_code(client, setup
363363
response = client.post("/api/v1/experiments/", json=experiment)
364364
assert response.status_code == 422
365365
response_data = response.json()
366-
assert response_data["detail"][0]["msg"] == "Invalid Gene Ontology accession."
366+
assert "Invalid Gene Ontology accession." in response_data["detail"][0]["msg"]
367367

368368

369369
def test_cannot_create_experiment_that_keyword_label_is_other_without_description(client, setup_router_db):

0 commit comments

Comments
 (0)