🐛 fix env var not override dotenv file (#1052)

This commit is contained in:
Ju4tCode 2022-06-18 14:47:42 +08:00 committed by GitHub
parent a62a49d477
commit 7b06469a30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 3 deletions

View File

@ -83,8 +83,7 @@ class CustomEnvSettings(EnvSettingsSource):
d[field.alias] = env_val d[field.alias] = env_val
if env_file_vars: if env_file_vars:
for env_name, env_val in env_file_vars.items(): for env_name in env_file_vars.keys():
if (env_val is None or len(env_val) == 0) and env_name in env_vars:
env_val = env_vars[env_name] env_val = env_vars[env_name]
try: try:
if env_val: if env_val:

View File

@ -2,3 +2,4 @@ LOG_LEVEL=TRACE
NICKNAME=["test"] NICKNAME=["test"]
SUPERUSERS=["test", "fake:faketest"] SUPERUSERS=["test", "fake:faketest"]
CONFIG_FROM_ENV= CONFIG_FROM_ENV=
CONFIG_OVERRIDE=old

View File

@ -3,6 +3,7 @@ import os
import pytest import pytest
os.environ["CONFIG_FROM_ENV"] = '{"test": "test"}' os.environ["CONFIG_FROM_ENV"] = '{"test": "test"}'
os.environ["CONFIG_OVERRIDE"] = "new"
@pytest.mark.asyncio @pytest.mark.asyncio
@ -25,6 +26,7 @@ async def test_init(nonebug_init):
config = get_driver().config config = get_driver().config
assert config.config_from_env == {"test": "test"} assert config.config_from_env == {"test": "test"}
assert config.config_override == "new"
assert config.config_from_init == "init" assert config.config_from_init == "init"
assert config.common_config == "common" assert config.common_config == "common"