From e4febcbd5db7c6c4dcfcde8f88a80699a9bb6871 Mon Sep 17 00:00:00 2001 From: signebedi Date: Fri, 6 Sep 2024 15:20:44 -0500 Subject: [PATCH] Fixed: new pydantic version issue with zoneinfo typesetting (#345) --- libreforms_fastapi/utils/config.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libreforms_fastapi/utils/config.py b/libreforms_fastapi/utils/config.py index 5cc8f36..049cc09 100644 --- a/libreforms_fastapi/utils/config.py +++ b/libreforms_fastapi/utils/config.py @@ -106,13 +106,16 @@ class Config(BaseSettings): @field_validator('TIMEZONE') def validate_timezone(cls, v): + # If it's already a ZoneInfo object, no need to re-validate + if isinstance(v, ZoneInfo): + return v + # If it's a string, attempt to create a ZoneInfo object try: - # Attempt to create a ZoneInfo object to validate the timezone tz = ZoneInfo(v) except ZoneInfoNotFoundError: # If the timezone is not found, raise a ValueError raise ValueError(f'Invalid timezone: {v}') - # Return the original string value, or you could return ZoneInfo(v) to store the object + # Return the ZoneInfo object to ensure proper timezone handling return tz # APP_STARTUP_TIME: datetime = datetime.now(ZoneInfo(os.getenv('TIMEZONE', 'America/New_York')))