Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: 修复 dotenv 配置项为 None 将会跳过赋值 #2143

Merged
merged 43 commits into from Jul 4, 2023
Merged

Fix: 修复 dotenv 配置项为 None 将会跳过赋值 #2143

merged 43 commits into from Jul 4, 2023

Conversation

eya46
Copy link
Contributor

@eya46 eya46 commented Jul 1, 2023

感觉是bug #2142

@codecov
Copy link

codecov bot commented Jul 1, 2023

Codecov Report

Merging #2143 (7fc1d13) into master (c40b95f) will decrease coverage by 0.03%.
The diff coverage is 87.50%.

@@            Coverage Diff             @@
##           master    #2143      +/-   ##
==========================================
- Coverage   89.73%   89.70%   -0.03%     
==========================================
  Files          46       46              
  Lines        3340     3343       +3     
==========================================
+ Hits         2997     2999       +2     
- Misses        343      344       +1     
Flag Coverage Δ
unittests 89.70% <87.50%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
nonebot/config.py 93.68% <87.50%> (-0.89%) ⬇️

@github-actions
Copy link
Contributor

github-actions bot commented Jul 1, 2023

🚀 Deployed on https://deploy-preview-2143--nonebot2.netlify.app

@github-actions github-actions bot temporarily deployed to pull request July 1, 2023 14:21 Inactive
Copy link
Member

@yanyongyu yanyongyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该替换这两行的默认值为 pydantic.fields.Undefined 然后下面改为is not undefined

env_val: Optional[str] = None
for env_name in field.field_info.extra["env_names"]:
env_val = env_vars.get(env_name)

@yanyongyu yanyongyu added the bug Something isn't working label Jul 1, 2023
@eya46
Copy link
Contributor Author

eya46 commented Jul 2, 2023

应该替换这两行的默认值为 pydantic.fields.Undefined 然后下面改为is not undefined

env_val: Optional[str] = None
for env_name in field.field_info.extra["env_names"]:
env_val = env_vars.get(env_name)

env_val: Optional[str] = Undefined #46
for env_name in field.field_info.extra["env_names"]: #47
    env_val = env_vars.get(env_name) #48
# ...
if is_complex:
    # ...
elif env_val is not Undefined:
    d[field.alias] = env_val

这样改好像会导致pydantic报错

  File "pydantic\env_settings.py", line 39, in pydantic.env_settings.BaseSettings.__init__
  File "pydantic\main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 3 validation errors for Config
  driver
none is not an allowed value (type=type_error.none.not_allowed)
  host
none is not an allowed value (type=type_error.none.not_allowed)
  session_expire_timeout
none is not an allowed value (type=type_error.none.not_allowed)

@yanyongyu
Copy link
Member

49行get的默认值呢?

@github-actions github-actions bot temporarily deployed to pull request July 2, 2023 05:44 Inactive
@github-actions github-actions bot temporarily deployed to pull request July 2, 2023 05:51 Inactive
@github-actions github-actions bot temporarily deployed to pull request July 3, 2023 11:52 Inactive
@github-actions github-actions bot temporarily deployed to pull request July 3, 2023 12:14 Inactive
@github-actions github-actions bot temporarily deployed to pull request July 4, 2023 02:30 Inactive
@yanyongyu yanyongyu changed the title 修复Config赋值的bug:值为None将会跳过赋值 Fix: 修复 dotenv 配置项为 None 将会跳过赋值 Jul 4, 2023
@yanyongyu yanyongyu merged commit 0033d7c into nonebot:master Jul 4, 2023
18 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

None yet

2 participants