Skip to content

Commit 039e49f

Browse files
Python: small fix for logging in declarative (#2341)
* small fix for logging in declarative * fix spaces in string
1 parent 61dbacd commit 039e49f

File tree

1 file changed

+16
-8
lines changed
  • python/packages/declarative/agent_framework_declarative

1 file changed

+16
-8
lines changed

python/packages/declarative/agent_framework_declarative/_models.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,38 @@
2323

2424

2525
@overload
26-
def _try_powerfx_eval(value: None) -> None: ...
26+
def _try_powerfx_eval(value: None, log_value: bool = True) -> None: ...
2727

2828

2929
@overload
30-
def _try_powerfx_eval(value: str) -> str: ...
30+
def _try_powerfx_eval(value: str, log_value: bool = True) -> str: ...
3131

3232

33-
def _try_powerfx_eval(value: str | None) -> str | None:
34-
"""Check if a value refers to a environment variable and parse it if so."""
33+
def _try_powerfx_eval(value: str | None, log_value: bool = True) -> str | None:
34+
"""Check if a value refers to a environment variable and parse it if so.
35+
36+
Args:
37+
value: The value to check.
38+
log_value: Whether to log the full value on error or just a snippet.
39+
"""
3540
if value is None:
3641
return value
3742
if not value.startswith("="):
3843
return value
3944
if engine is None:
4045
logger.warning(
41-
f"PowerFx engine not available for evaluating value: {value}"
42-
"Ensure you are on python 3.13 or less and have the powerfx package installed."
46+
"PowerFx engine not available for evaluating values starting with '='. "
47+
"Ensure you are on python 3.13 or less and have the powerfx package installed. "
4348
"Otherwise replace all powerfx statements in your yaml with strings."
4449
)
4550
return value
4651
try:
4752
return engine.eval(value[1:], symbols={"Env": dict(os.environ)})
4853
except Exception as exc:
49-
logger.info("PowerFx evaluation failed for value '%s': %s", value, exc)
54+
if log_value:
55+
logger.debug("PowerFx evaluation failed for value '%s': %s", value, exc)
56+
else:
57+
logger.debug("PowerFx evaluation failed for value (first five characters shown) '%s': %s", value[:5], exc)
5058
return value
5159

5260

@@ -324,7 +332,7 @@ def __init__(
324332
)
325333
self.endpoint = _try_powerfx_eval(endpoint)
326334
# Support both 'apiKey' and 'key' fields, with 'key' taking precedence if both are provided
327-
self.apiKey = _try_powerfx_eval(key if key else apiKey)
335+
self.apiKey = _try_powerfx_eval(key if key else apiKey, False)
328336

329337

330338
class AnonymousConnection(Connection):

0 commit comments

Comments
 (0)