Skip to content

fix(python): handle numeric timestamps and build dates in looksLikePythonVersion - #474

Merged
Malaydewangan09 merged 2 commits into
kestra-io:mainfrom
ADITYASINGH1206:fix/472-python-environment-manager-version-nfe
Oct 26, 2026
Merged

Malaydewangan09 merged 2 commits into
kestra-io:mainfrom
ADITYASINGH1206:fix/472-python-environment-manager-version-nfe

Conversation

@ADITYASINGH1206

Copy link
Copy Markdown
Contributor

Closes #472.

What problem does this PR solve?

In io.kestra.plugin.scripts.python.internals.PythonEnvironmentManager, when inferring the Python version from a container image tag, looksLikePythonVersion() parsed the tag prefix with Integer.parseInt(version.split("\\.")[0]) and checked major >= 2.

When custom Docker images use numeric timestamps or build dates (e.g., python:20261021113000 or python:20241021), this resulted in:

  1. NumberFormatException when numeric tags exceed Integer.MAX_VALUE (e.g., 14-digit timestamps), aborting task execution during environment setup.
  2. Falsely accepting build dates (e.g., 20241021 >= 2) as valid Python versions, causing package resolution and cache key generation to fail downstream.

What changes are made in this PR?

  1. PythonEnvironmentManager.java:
    • Added null/empty guard returning false.
    • Wrapped Integer.parseInt() in a try-catch block catching NumberFormatException and returning false.
    • Validated that the major version is within valid Python major versions (major >= 2 && major <= 9), rejecting 4-digit years, 8-digit dates, and build timestamps while accepting Python 2 and 3.
  2. PythonVersionParserTest.java:
    • Added unit test cases for numeric timestamps (20261021113000), build dates (20241021), build years (2024.1), and invalid/null inputs.

@kestrabot kestrabot Bot added area/plugin Plugin-related issue or feature request kind/external Pull requests raised by community contributors labels Oct 22, 2026
@kestrabot
kestrabot Bot requested review from a team and Malaydewangan09 October 22, 2026 16:31
@github-project-automation github-project-automation Bot moved this to To review in Pull Requests Oct 22, 2026
@Malaydewangan09

Copy link
Copy Markdown
Member

Thanks, the fix is right: the try/catch stops timestamp tags from crashing the task, and the <= 9 bound rejects build dates while still accepting future Python majors. I removed the null/empty guard because the only caller passes a regex match of digits through Optional.filter, so it can't be reached, and dropped its test. I also updated the Javadoc.

I pushed these tweaks.

@Malaydewangan09
Malaydewangan09 merged commit cd7fbae into kestra-io:main Oct 26, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from To review to Done in Pull Requests Oct 26, 2026
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: Done

2 participants