kestra-io / kestra-io/plugin-scripts

Python tasks fail with NullPointerException on Windows: HOME is not defined

Aperta
#441 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

area/backend area/plugin
Lingua principale
Java
Stelle
19
Fork
34
Merge medio
2g 12h
PR unite (30g)
9

Descrizione

What happens

On Windows, every io.kestra.plugin.scripts.python.Script task fails before beforeCommands or the script are reached:

java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.toString()" because "<parameter2>" is null
	at java.base/java.lang.String.replace(Unknown Source)
	at io.kestra.plugin.scripts.python.internals.PythonDependenciesResolver.getUvCmd(PythonDependenciesResolver.java:339)
	at io.kestra.plugin.scripts.python.internals.PythonDependenciesResolver.findPython(PythonDependenciesResolver.java:566)
	at io.kestra.plugin.scripts.python.internals.PythonDependenciesResolver.findLocalPythonVersion(PythonDependenciesResolver.java:152)
	at io.kestra.plugin.scripts.python.internals.PythonEnvironmentManager.setup(PythonEnvironmentManager.java:79)
	at io.kestra.plugin.scripts.python.Script.run(Script.java:358)

Cause

PythonDependenciesResolver.java:36:

private static final String HOME_ENV = System.getenv("HOME");

Windows does not define HOME (it has USERPROFILE), so HOME_ENV is null. Two consequences:

  1. Line 339Optional.ofNullable(System.getenv("UV_PATH")).orElse("$HOME/.local/bin/uv".replace("$HOME", HOME_ENV))String.replace(target, null). Because orElse evaluates its argument eagerly, this throws even when UV_PATH is set, so there is no way to configure around it.
  2. Lines 384, 540, 577env.put("HOME", HOME_ENV) on a ProcessBuilder environment. Windows' ProcessEnvironment rejects a null value, which surfaces as a second NPE: Cannot invoke "String.indexOf(int)" because "<parameter1>" is null.

Code is identical in v1.9.8 and v1.9.10.

Reproduction

Kestra 1.3.37 standalone on Windows Server 2022, plugin-script-python 1.9.8, Process task runner:

id: python-probe
namespace: test
tasks:
  - id: hello
    type: io.kestra.plugin.scripts.python.Script
    taskRunner:
      type: io.kestra.plugin.core.runner.Process
    script: |
      print("hello")

Fails the same way with no Python installed, with system Python 3.12 + uv 0.12.15 on PATH, with a uv-managed interpreter and UV_PYTHON_INSTALL_DIR set, and with pythonVersion named explicitly.

Confirmation

Setting HOME in the server's environment removes the NPE, and the resolver then works correctly on Windows:

uv --version                                 → uv 0.12.15 (x86_64-pc-windows-msvc)
uv python find --system --no-managed-python  → C:\Python312\python.exe
C:\Python312\python.exe --version            → Python 3.12.10

(The task then needs interpreter: ["cmd", "/c"], since AbstractExecScript defaults to /bin/sh -c — a separate matter — after which it runs: cmd /c python3 …py, exit 0.)

Suggested fix

Resolve the home directory portably — HOME, then USERPROFILE, then System.getProperty("user.home"), which the JVM always sets — and make line 339 use orElseGet so the default path is not computed when UV_PATH is set. Happy to open a PR.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in PythonDependenciesResolver.java, in particolare nella dichiarazione di HOME_ENV e alle righe 339, 384, 540 e 577, quindi segui la chiamata da PythonEnvironmentManager.setup e Script.run. Riproduci il problema di Windows con l’attività Python fornita e verifica che la risoluzione raggiunga lo script senza eccezioni relative a HOME, anche quando UV_PATH è impostato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java, python
Ambito
backend
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Attiva
Chiarezza
Specificata chiaramente
Idoneità per principianti
76/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.