Skip to content

Commit

Permalink
Fix prefect config view not showing .env file settings (#15922)
Browse files Browse the repository at this point in the history
  • Loading branch information
GalLadislav authored Nov 4, 2024
1 parent 190c994 commit 103c925
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/prefect/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def _process_toml_settings(
_process_setting(setting, env_value, "env")

# Process settings from .env file
for key, value in dotenv_values().items():
for key, value in dotenv_values(".env").items():
if key in VALID_SETTING_NAMES:
setting = _get_settings_fields(prefect.settings.Settings)[key]
if setting.name in processed_settings or value is None:
Expand Down
44 changes: 43 additions & 1 deletion tests/cli/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
FROM_DEFAULT = "(from defaults)"
FROM_ENV = "(from env)"
FROM_PROFILE = "(from profile)"
FROM_DOT_ENV = "(from .env)"
FROM_DOT_ENV = "(from .env file)"
FROM_PREFECT_TOML = "(from prefect.toml)"
FROM_PYPROJECT_TOML = "(from pyproject.toml)"

Expand Down Expand Up @@ -552,6 +552,48 @@ def test_view_shows_secrets(monkeypatch, command):
assert f"PREFECT_API_DATABASE_PASSWORD='None' {FROM_DEFAULT}" in lines


def test_view_with_env_file(tmp_path):
with tmpchdir(tmp_path):
with open(".env", "w") as f:
f.write("PREFECT_CLIENT_RETRY_EXTRA_CODES=300\n")

res = invoke_and_assert(["config", "view"])

assert "PREFECT_CLIENT_RETRY_EXTRA_CODES='300'" in res.stdout
assert FROM_DOT_ENV in res.stdout


def test_view_with_env_file_and_env_var(monkeypatch, tmp_path):
monkeypatch.setenv("PREFECT_CLIENT_RETRY_EXTRA_CODES", "400")

with tmpchdir(tmp_path):
with open(".env", "w") as f:
f.write("PREFECT_CLIENT_RETRY_EXTRA_CODES=300\n")

res = invoke_and_assert(["config", "view"])

assert "PREFECT_CLIENT_RETRY_EXTRA_CODES='400'" in res.stdout
assert FROM_DOT_ENV not in res.stdout


def test_view_with_env_file_and_profile(tmp_path):
with tmpchdir(tmp_path):
with open(".env", "w") as f:
f.write("PREFECT_CLIENT_RETRY_EXTRA_CODES=300\n")

with prefect.context.use_profile(
prefect.settings.Profile(
name="foo",
settings={PREFECT_CLIENT_RETRY_EXTRA_CODES: [400]},
),
include_current_context=False,
):
res = invoke_and_assert(["config", "view"])

assert "PREFECT_CLIENT_RETRY_EXTRA_CODES='300'" in res.stdout
assert FROM_DOT_ENV in res.stdout


def test_view_with_prefect_toml_file(tmp_path):
with tmpchdir(tmp_path):
toml_data = {"client": {"retry_extra_codes": "300"}}
Expand Down

0 comments on commit 103c925

Please sign in to comment.