Skip to content

Commit

Permalink
Fix: 声明为 str 的配置项在 dotenv 中写为纯数字时在 Pydantic 2 下的解析错误
Browse files Browse the repository at this point in the history
写的有点暴力
  • Loading branch information
lgc2333 authored Jul 6, 2024
1 parent 4d070f5 commit a56f5cc
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion nonebot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ def __call__(self) -> dict[str, Any]:
# remain user custom config
for env_name in env_file_vars:
env_val = env_vars[env_name]
if env_val and (val_striped := env_val.strip()):
if env_val and (val_striped := env_val.strip()).startswith(("[", "{")):
# there's a value, decode that as JSON
# fuck pydantic2's type_validate_python, just load arrays and objects
try:
env_val = json.loads(val_striped)
except ValueError:
Expand Down

0 comments on commit a56f5cc

Please sign in to comment.