Skip to content

fix: convert Python booleans to valid Python literals in Kestra.outputs()#339

Open
nancysangani wants to merge 2 commits intokestra-io:mainfrom
nancysangani:fix/python-boolean-output
Open

fix: convert Python booleans to valid Python literals in Kestra.outputs()#339
nancysangani wants to merge 2 commits intokestra-io:mainfrom
nancysangani:fix/python-boolean-output

Conversation

@nancysangani
Copy link
Copy Markdown

@nancysangani nancysangani commented Mar 17, 2026

Fixes #191

Problem

When Kestra.outputs() is called with a Python boolean, json.dumps serializes it as JSON true/false. When a downstream Python task references it via {{outputs.task.vars.my_bool}}, Pebble renders it as true — not a valid Python identifier, causing a NameError in the downstream task.

Fix

Added _convert_booleans() in kestra.py that recursively converts bool values to "True"/"False" strings before serialization. All other types and languages are unaffected.

Files Changed

  • kestra.py — added _convert_booleans(), updated outputs() to call it
  • PythonTest.java — updated bool assertions to match new string representation
  • ScriptTest.java — same

…uts() to prevent NameError in downstream tasks
Copilot AI review requested due to automatic review settings March 17, 2026 14:41
@github-project-automation github-project-automation bot moved this to To review in Pull Requests Mar 17, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Python helper library (kestra.py) and corresponding Java tests to treat boolean output values emitted via Kestra.outputs(...) as strings (e.g., "True") rather than JSON booleans.

Changes:

  • Added a recursive boolean-to-string conversion in Kestra.outputs(...) before JSON serialization.
  • Updated Python plugin tests to assert "True" (string) instead of true (boolean) for output vars.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
plugin-script-python/src/main/resources/kestra.py Adds boolean stringification logic for values passed to Kestra.outputs(...).
plugin-script-python/src/test/java/io/kestra/plugin/scripts/python/ScriptTest.java Updates expected bool output var type/value in plugin-level script test.
plugin-script-python/src/test/java/io/kestra/core/tasks/scripts/PythonTest.java Updates expected boolean output var type/value in deprecated core Python task tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

assertThat(run.getVars().get("test"), is("value"));
assertThat(run.getVars().get("int"), is(2));
assertThat(run.getVars().get("bool"), is(true));
assertThat(run.getVars().get("bool"), is("True"));
Comment on lines +25 to 39
@staticmethod
def _convert_booleans(obj):
if isinstance(obj, bool):
return str(obj)
elif isinstance(obj, dict):
return {k: Kestra._convert_booleans(v) for k, v in obj.items()}
elif isinstance(obj, list):
return [Kestra._convert_booleans(item) for item in obj]
return obj

@staticmethod
def outputs(map):
Kestra._send({
"outputs": map
"outputs": Kestra._convert_booleans(map)
})

assertThat(run.getExitCode(), is(0));
assertThat(run.getVars().get("ok"), is(true));
assertThat(run.getVars().get("ok"), is("True"));
Comment on lines +247 to +252
assertThat(run.getVars().get("bool"), is("True"));
assertThat(run.getVars().get("float"), is(3.65));

assertThat(run.getVars().get("test"), is("value"));
assertThat(run.getVars().get("int"), is(2));
assertThat(run.getVars().get("bool"), is(true));
assertThat(run.getVars().get("bool"), is("True"));
@nancysangani
Copy link
Copy Markdown
Author

/cc @fdelbrayelle
/cc @Ben8t

@fdelbrayelle fdelbrayelle added area/plugin Plugin-related issue or feature request kind/external Pull requests raised by community contributors labels Mar 17, 2026
@fdelbrayelle fdelbrayelle requested review from a team and Malaydewangan09 March 17, 2026 15:16
Copy link
Copy Markdown
Member

@fdelbrayelle fdelbrayelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nancysangani Proove it works by sharing screenshots of passing flows + logs please 🙏

@nancysangani
Copy link
Copy Markdown
Author

@fdelbrayelle after looking into this further, it looks like the fix spans two repos. The kestraLibs test installs kestra directly from PyPI (pip install kestra), so the fix in kestra.py here won’t take effect until a new version is published from kestra-io/libs.

I’ve opened a corresponding PR there with the same fix — kestra-io/libs#39

Could you advise how you'd prefer to handle the kestraLibs test? Should it use the local bundled kestra.py, or should we wait for the kestra-io/libs change to be released?

@nancysangani
Copy link
Copy Markdown
Author

nancysangani commented Mar 17, 2026

@fdelbrayelle Here are the screenshots proving the bug and the fix.

Screenshot 1 (before fix): val = true causes NameError: name 'true' is not defined in the downstream task
Screenshot 2026-03-17 220809

Screenshot 2 (after fix): Both tasks pass successfully once _convert_booleans() is applied.
Screenshot 2026-03-17 223112

The kestraLibs test in this repo installs kestra via pip install kestra which uses the current PyPI version. The core fix is in kestra-io/libs#39 — once that is released to PyPI, the failing tests here will reflect the fix automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/plugin Plugin-related issue or feature request kind/external Pull requests raised by community contributors

Projects

Status: To review

Development

Successfully merging this pull request may close these issues.

Kestra task output method - Python boolean not rendered properly

4 participants