Skip to content

Commit

Permalink
Fix frequency validation error for scheduled messages (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
JudsonStevens authored Oct 1, 2023
1 parent 85f321f commit 10b102b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions modules/models/scheduled_message_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from datetime import datetime
from enum import Enum

from pydantic import Field, validator
from pydantic import Field, field_validator
from pydantic_core.core_schema import FieldValidationInfo

from modules.models.shared_models import AirtableRowBaseModel

Expand Down Expand Up @@ -60,17 +61,19 @@ class ScheduledMessageInfo(AirtableRowBaseModel):
description="When to send the message - this is calculated using a formula on the Airtable table",
)

@validator("frequency")
def frequency_must_be_valid( # noqa: N805, RUF100
@field_validator("frequency")
def frequency_must_be_valid(
cls: "ScheduledMessageInfo", # noqa: N805
frequency: str,
info: FieldValidationInfo, # noqa: ARG002
) -> str:
"""Validate that the passed in frequency is valid.
"""Validate that the passed in frequency is a valid option.
:param frequency: The frequency to validate.
:param info: The field validation info.
:return: The frequency if it is valid.
"""
if frequency not in FrequencyEnum.__members__:
if frequency.lower() not in FrequencyEnum.__members__:
exception_message = f"Frequency must be one of {FrequencyEnum.__members__.keys()}"
raise ValueError(exception_message)
return frequency
return frequency.lower()

0 comments on commit 10b102b

Please sign in to comment.