From 21cc0a406b283815a96158f240a4dfda266886b0 Mon Sep 17 00:00:00 2001 From: Brian Brondel Date: Mon, 29 Jul 2024 17:02:29 -0700 Subject: [PATCH] Move from deprecated validator decorator to field_decorator --- python/lsst/consdb/pqserver.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/lsst/consdb/pqserver.py b/python/lsst/consdb/pqserver.py index 81da069d..1d30167d 100644 --- a/python/lsst/consdb/pqserver.py +++ b/python/lsst/consdb/pqserver.py @@ -26,7 +26,7 @@ from fastapi import FastAPI, APIRouter, Depends, Path import sqlalchemy import sqlalchemy.dialects.postgresql -from pydantic import BaseModel, Field, validator +from pydantic import BaseModel, Field, field_validator from safir.metadata import Metadata, get_metadata from .utils import setup_logging, setup_postgres @@ -482,16 +482,16 @@ class AddKeyRequestModel(BaseModel): ..., title="IVOA Unified Content Descriptor (https://www.ivoa.net/documents/UCD1+/)" ) - @validator("unit") - def validate_unit(cls, v): + @field_validator("unit") + def validate_unit(v): try: unit = astropy.units.Unit(v) except ValueError: raise ValueError(f"'{v}' is a not a valid unit.") return v - @validator("ucd") - def validate_ucd(cls, v): + @field_validator("ucd") + def validate_ucd(v): if not astropy.io.votable.ucd.check_ucd(v): raise ValueError(f"'{v}' is not a valid IVOA UCD.") return v