Skip to content

Commit

Permalink
Fix parsing of string number of seconds for timeout
Browse files Browse the repository at this point in the history
Pydantic's built-in timedelta parsing does not support seconds as
a string, so add a validator to handle (and force) that.
  • Loading branch information
rra committed Jul 10, 2024
1 parent 02f4b24 commit a9ac4c0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/vocutouts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@ def _parse_timedelta(cls, v: str | float | timedelta) -> float | timedelta:
except ValueError:
return parse_timedelta(v)

@field_validator("timeout", mode="before")
@classmethod
def _parse_timedelta_seconds(
cls, v: str | float | timedelta
) -> float | timedelta:
"""Support human-readable timedeltas."""
if not isinstance(v, str):
return v
return int(v)

@property
def arq_redis_settings(self) -> RedisSettings:
"""Redis settings for arq."""
Expand Down

0 comments on commit a9ac4c0

Please sign in to comment.