Skip to content

Commit 559cb2b

Browse files
committed
Update Pydantic validators to use new field_validator decorator
1 parent 7bd044a commit 559cb2b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

cloudproxy/main.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from fastapi.middleware.cors import CORSMiddleware
1616
from fastapi.openapi.docs import get_swagger_ui_html
1717
from fastapi.openapi.utils import get_openapi
18-
from pydantic import BaseModel, IPvAnyAddress, Field, validator
18+
from pydantic import BaseModel, IPvAnyAddress, Field, field_validator
1919

2020
from cloudproxy.providers import settings
2121
from cloudproxy.providers.settings import delete_queue, restart_queue
@@ -129,8 +129,10 @@ class ProxyAddress(BaseModel):
129129
auth_enabled: bool = True
130130
url: Optional[str] = None
131131

132-
@validator('url', always=True)
133-
def set_url(cls, v, values):
132+
@field_validator('url', mode='before')
133+
@classmethod
134+
def set_url(cls, v, info):
135+
values = info.data
134136
ip = str(values.get('ip'))
135137
port = values.get('port', 8899)
136138
if values.get('auth_enabled'):
@@ -368,8 +370,10 @@ class ProviderUpdateRequest(BaseModel):
368370
min_scaling: int = Field(ge=0, description="Minimum number of proxy instances")
369371
max_scaling: int = Field(ge=0, description="Maximum number of proxy instances")
370372

371-
@validator('max_scaling')
372-
def max_scaling_must_be_greater_than_min(cls, v, values):
373+
@field_validator('max_scaling')
374+
@classmethod
375+
def max_scaling_must_be_greater_than_min(cls, v, info):
376+
values = info.data
373377
if 'min_scaling' in values and v < values['min_scaling']:
374378
raise ValueError('max_scaling must be greater than or equal to min_scaling')
375379
return v

0 commit comments

Comments
 (0)