Fix: Strip whitespace from env vars before validation
Pydantic cannot parse 'true ' (with trailing spaces) as boolean. Added field_validator to automatically strip whitespace from all string inputs.
This commit is contained in:
parent
dfe2bed11f
commit
f4f2e35590
@ -5,6 +5,7 @@ Handles environment variables and application settings
|
||||
|
||||
import os
|
||||
from typing import List
|
||||
from pydantic import field_validator
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
|
||||
@ -77,6 +78,14 @@ class Settings(BaseSettings):
|
||||
GITHUB_TOKEN: str = ""
|
||||
GITHUB_REPO: str = "ct/bmc_hub"
|
||||
|
||||
@field_validator('*', mode='before')
|
||||
@classmethod
|
||||
def strip_whitespace(cls, v):
|
||||
"""Strip leading/trailing whitespace from string values"""
|
||||
if isinstance(v, str):
|
||||
return v.strip()
|
||||
return v
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
case_sensitive = True
|
||||
|
||||
Loading…
Reference in New Issue
Block a user