Skip to content

Commit

Permalink
Move from deprecated validator decorator to field_decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrondel committed Jul 30, 2024
1 parent 6007ab8 commit 21cc0a4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions python/lsst/consdb/pqserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 21cc0a4

Please sign in to comment.