fix: adding support for environment variables type dict (#6672)

Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>
This commit is contained in:
Fredy Sierra 2025-02-10 19:56:58 +01:00 committed by GitHub
parent 7860055f8c
commit 13839b4273
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,6 +3,7 @@ import os
import pathlib
import platform
import sys
from ast import literal_eval
from types import UnionType
from typing import Any, MutableMapping, get_args, get_origin
from uuid import uuid4
@ -72,6 +73,9 @@ def load_from_env(cfg: AppConfig, env_or_toml_dict: dict | MutableMapping[str, s
# Attempt to cast the env var to type hinted in the dataclass
if field_type is bool:
cast_value = str(value).lower() in ['true', '1']
# parse dicts like SANDBOX_RUNTIME_STARTUP_ENV_VARS
elif get_origin(field_type) is dict:
cast_value = literal_eval(value)
else:
cast_value = field_type(value)
setattr(sub_config, field_name, cast_value)