Skip to content

Commit

Permalink
Fixed: new pydantic version issue with zoneinfo typesetting (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
signebedi committed Sep 6, 2024
1 parent e02cb69 commit e4febcb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions libreforms_fastapi/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')))
Expand Down

0 comments on commit e4febcb

Please sign in to comment.