From 8d6dc8815d702a9bc6a9b0b238ae43d80cd93ccd Mon Sep 17 00:00:00 2001 From: estebanthi Date: Mon, 20 Oct 2025 12:17:30 +0200 Subject: [PATCH] Updated update validators --- src/healthchecks_io/schemas/checks.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/healthchecks_io/schemas/checks.py b/src/healthchecks_io/schemas/checks.py index ff5bdff..32c3796 100644 --- a/src/healthchecks_io/schemas/checks.py +++ b/src/healthchecks_io/schemas/checks.py @@ -128,33 +128,33 @@ class CheckCreate(BaseModel): @field_validator("schedule") @classmethod - def validate_schedule(cls, value: str) -> str: + def validate_schedule(cls, value: str | None) -> str: """Validates that the schedule is a valid cron expression.""" - if not croniter.is_valid(value): + if value and not croniter.is_valid(value): raise ValueError("Schedule is not a valid cron expression") return value @field_validator("tz") @classmethod - def validate_tz(cls, value: str) -> str: + def validate_tz(cls, value: str | None) -> str: """Validates that the timezone is a valid timezone string.""" - if value not in pytz.all_timezones: + if value and value not in pytz.all_timezones: raise ValueError("Tz is not a valid timezone") return value @field_validator("methods") @classmethod - def validate_methods(cls, value: str) -> str: + def validate_methods(cls, value: str | None) -> str: """Validate that methods.""" - if value not in ("", "POST"): - raise ValueError("Methods is invalid, it should be either an empty string or POST") - return value + if value and value != "POST": + raise ValueError("Methods is invalid, it should be either an empty string, None, or POST") + return "" @field_validator("unique") @classmethod - def validate_unique(cls, value: List[Optional[str]]) -> List[Optional[str]]: + def validate_unique(cls, value: List[Optional[str]] | None) -> List[Optional[str]]: """Validate unique list.""" - for unique in value: + for unique in value or []: if unique not in ("name", "tags", "timeout", "grace"): raise ValueError( "Unique is not valid. Unique can only be name, tags, timeout, and grace or an empty list"