Skip to content

Python: [Bug]: Declarative: PowerFx undefined-variable errors crash on non-English system locales #4321

@corradopignato

Description

@corradopignato

Description

Package: agent-framework-declarative
Component: DeclarativeWorkflowState.eval() in _declarative_base.py
Affected versions: ≤ 1.0.0b260225

On machines where the UI locale is not English (e.g. it-IT, fr-FR,
de-DE), evaluating a Power Fx expression that references an as-yet-unset
state variable
raises an unhandled ValueError and crashes the entire workflow,
instead of returning None gracefully.

This makes patterns like the following impossible:
-- Local.StatusConversationId is undefined --

- kind: InvokeAzureAgent
  conversationId: =Local.StatusConversationId   # crashes on non-EN locale
  ...

the =Local.StatusConversationId
expression crashes before the value can be read.

Root Cause

eval() already contains a guard to handle undefined-variable errors gracefully:

except ValueError as e:
    error_msg = str(e)
    if "isn't recognized" in error_msg or "Name isn't valid" in error_msg:
        return None   # treat missing variable as None
    raise

The guard matches against English Power Fx error strings. However,
errors are produced in the language determined by
CultureInfo.CurrentUICulturenot CurrentCulture. The existing code
forced CurrentCulture to "en-US" before calling the engine, but left
CurrentUICulture unchanged. On an Italian system this yields:

ValueError: Power Fx failed compilation:
    Il nome non è valido. "StatusConversationId" non riconosciuto.

…which matches neither "isn't recognized" nor "Name isn't valid", so the
exception propagates and the workflow terminates with an unhandled traceback.

Steps to Reproduce

  1. Run any declarative workflow that uses =Local.<Variable> in an expression
    on a machine whose UI culture is not en-US (e.g. set
    LANG=it_IT.UTF-8 or run on an Italian macOS/Windows installation).
  2. Ensure the variable is set before the expression is evaluated (to confirm
    the variable itself is not the issue, but merely the locale of the error
    message).

Fix

In _declarative_base.py, force both CurrentCulture and
CurrentUICulture to "en-US" before calling the Power Fx engine, and restore
both in the finally block:

original_culture = CultureInfo.CurrentCulture
original_ui_culture = CultureInfo.CurrentUICulture          # ← add
CultureInfo.CurrentCulture = CultureInfo("en-US")
CultureInfo.CurrentUICulture = CultureInfo("en-US")         # ← add
try:
    return engine.eval(formula, symbols=symbols)
finally:
    CultureInfo.CurrentCulture = original_culture
    CultureInfo.CurrentUICulture = original_ui_culture      # ← add

Code Sample

Error Messages / Stack Traces

Package Versions

1.0.0b260225

Python Version

3.12

Additional Context

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpythonv1.0Features being tracked for the version 1.0 GAworkflowsRelated to Workflows in agent-framework

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions