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

无法读取环境变量配置的问题 #15

Closed
felinae98 opened this issue Jun 7, 2022 · 2 comments
Closed

无法读取环境变量配置的问题 #15

felinae98 opened this issue Jun 7, 2022 · 2 comments

Comments

@felinae98
Copy link

class Config(BaseModel, extra=Extra.ignore):

这个地方应该继承BaseSettings
因为nonebot的global_config对环境变量和envfile的处理有差异,写在envfile里的文件会全部load进global_config,插件config从global_config中初始化会带上global_config load的envfile里的值
但是,global_config不会load自己不认识的环境变量,所以如果这里使用BaseModel的话,是没有办法将环境变量的值引入插件config的,需要使用BaseSetting来自己读取环境变量中的值

@he0119
Copy link
Owner

he0119 commented Jun 7, 2022

惊,原来还有这种坑。nb的文档是不是也该改改

@he0119
Copy link
Owner

he0119 commented Jun 7, 2022

我去问了一下,就是这样设计的。必须要先在 .env 文件中配置所需配置项,nonebot 才会在环境变量中读取。

CUSTOM_CONFIG2= # 留空则从系统环境变量读取,如不存在则为空字符串

文档里确实没有说清楚。

@he0119 he0119 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants