Skip to content

Commit

Permalink
Adopt Pydantic 2 @model_validator
Browse files Browse the repository at this point in the history
The original @validator is deprecated
  • Loading branch information
jonathansick committed Jan 3, 2024
1 parent f411d10 commit df251db
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/noteburst/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

from enum import Enum
from pathlib import Path
from typing import Any, Mapping, Optional
from typing import Optional, Self

from arq.connections import RedisSettings
from pydantic import Field, HttpUrl, RedisDsn, SecretStr, validator
from pydantic import Field, HttpUrl, RedisDsn, SecretStr, model_validator
from pydantic_settings import BaseSettings
from safir.arq import ArqMode
from safir.logging import LogLevel, Profile
Expand Down Expand Up @@ -47,6 +47,8 @@ class WorkerKeepAliveSetting(str, Enum):


class Config(BaseSettings):
"""Noteburst app configuration."""

name: str = Field("Noteburst", alias="SAFIR_NAME")

profile: Profile = Field(Profile.production, alias="SAFIR_PROFILE")
Expand Down Expand Up @@ -172,23 +174,21 @@ def aioredlock_redis_config(self) -> list[str]:
"""Redis configurations for aioredlock."""
return [str(self.identity_lock_redis_url)]

@validator("image_reference")
def is_image_ref_set(
cls, v: Optional[str], values: Mapping[str, Any]
) -> Optional[str]:
@model_validator(mode="after")
def is_image_ref_set(self) -> Self:
"""Validate that image_reference is set if image_selector is
set to reference.
"""
if (
v is None
and values["image_selector"] == JupyterImageSelector.reference
self.image_reference is None
and self.image_selector == JupyterImageSelector.reference
):
raise ValueError(
"Set NOTEBURST_WORKER_IMAGE_REFERENCE since "
"NOTEBURST_WORKER_IMAGE_SELECTOR is ``reference``."
)

return v
return self

@property
def parsed_worker_token_scopes(self) -> list[str]:
Expand Down

0 comments on commit df251db

Please sign in to comment.