Skip to content

Commit 4e39477

Browse files
committed
Add YAML string processing for env vars that are set as empty string
1 parent 8425b12 commit 4e39477

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

api/api_tests/util/string_processing/test_yaml.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ def test_env_var_overrides_default(self):
5252
result = substitute_env_vars_in_yaml_content("key: $TEST_VAR|default_value")
5353
assert result == "key: env_value"
5454

55+
def test_empty_string_treated_as_unset_uses_default(self):
56+
"""When primary var is set but empty, treat as unset and use default (avoids invalid YAML in lists)."""
57+
with patch.dict(os.environ, {"YOLOX_HTTP_ENDPOINT": ""}, clear=True):
58+
result = substitute_env_vars_in_yaml_content(
59+
'yolox_endpoints: [$GRPC|"page-elements:8001", $YOLOX_HTTP_ENDPOINT|"http://page-elements:8000/v1/infer"]'
60+
)
61+
assert result == 'yolox_endpoints: ["page-elements:8001", "http://page-elements:8000/v1/infer"]'
62+
5563
def test_missing_var_no_default(self):
5664
"""Test that missing variables without defaults become empty strings."""
5765
with patch.dict(os.environ, {}, clear=True):

api/src/nv_ingest_api/util/string_processing/yaml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def _replacer(match: re.Match) -> str:
4141
var_name = match.group("braced") or match.group("named")
4242
default_val = match.group("braced_default") or match.group("named_default")
4343

44-
# First try the primary env var
44+
# First try the primary env var (treat empty string as unset so default is used)
4545
value = os.environ.get(var_name)
46-
if value is not None:
46+
if value is not None and value != "":
4747
return _quote_if_needed(value)
4848

4949
# If primary is missing, try the default.

0 commit comments

Comments
 (0)