Skip to content

Commit b38f0bf

Browse files
committed
fix: refine environment variable override logic in config
- Updated the environment variable handling in get_specs to ensure overrides only occur if parameters are not specified in defaults or YAML files. - Improved logging to reflect the changes made by environment variable overrides.
1 parent 518d1fd commit b38f0bf

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

anomstack/config.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ def process_yaml_file(yaml_file: str):
4949
return
5050

5151
# Apply global environment variable overrides
52+
# Only override if the parameter is NOT specified in either defaults or specific YAML file
5253
for env_var in env_vars:
5354
if env_var in os.environ:
5455
param_key = env_var.replace("ANOMSTACK_", "").lower()
55-
yaml_value = metric_specs.get(param_key) or defaults.get(param_key)
56-
merged_specs[param_key] = os.getenv(env_var)
57-
logger.info(f"ENV OVERRIDE: {env_var} replaces {param_key} (was: {yaml_value}, now: {merged_specs[param_key]})")
56+
# Only override if the parameter is NOT specified in either defaults or specific YAML file
57+
if param_key not in metric_specs and param_key not in defaults:
58+
yaml_value = merged_specs.get(param_key)
59+
merged_specs[param_key] = os.getenv(env_var)
60+
logger.info(f"ENV OVERRIDE: {env_var} replaces {param_key} (was: {yaml_value}, now: {merged_specs[param_key]})")
5861

5962
# Apply metric batch-specific environment variable overrides
6063
# Pattern: ANOMSTACK__<METRIC_BATCH>__<PARAM>

0 commit comments

Comments
 (0)