🐛 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,9 +83,8 @@ class CustomEnvSettings(EnvSettingsSource):
d[field.alias] = env_val
if env_file_vars:
for env_name, env_val in env_file_vars.items():
if (env_val is None or len(env_val) == 0) and env_name in env_vars:
env_val = env_vars[env_name]
for env_name in env_file_vars.keys():
env_val = env_vars[env_name]
try:
if env_val:
env_val = settings.__config__.json_loads(env_val.strip())

View File

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

View File

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