From a21646d3984accf2d47fdfa93d49ea006c7fd7e6 Mon Sep 17 00:00:00 2001 From: Mariam Ahhttouche Date: Fri, 6 Mar 2026 17:44:41 +0000 Subject: [PATCH] Handle case when version given is an empty string in uv_python module --- plugins/modules/uv_python.py | 5 ++--- .../targets/uv_python/tasks/main.yaml | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/plugins/modules/uv_python.py b/plugins/modules/uv_python.py index e84448e651..e67cd4a7f0 100644 --- a/plugins/modules/uv_python.py +++ b/plugins/modules/uv_python.py @@ -118,10 +118,9 @@ class UV: self.bin_path = self.module.get_bin_path("uv", required=True) self._ensure_min_uv_version() try: - python_version = module.params["version"] - self.python_version = StrictVersion(python_version) + self.python_version = StrictVersion(module.params["version"]) self.python_version_str = str(self.python_version) - except ValueError: + except (ValueError, AttributeError): self.module.fail_json( msg="Unsupported version format. Valid version numbers consist of two or three dot-separated numeric components, \ with an optional 'pre-release' tag on the end (e.g. 3.12, 3.12.3, 3.15.0a5) are supported in this release." diff --git a/tests/integration/targets/uv_python/tasks/main.yaml b/tests/integration/targets/uv_python/tasks/main.yaml index 53cef8c90d..e7046b744a 100644 --- a/tests/integration/targets/uv_python/tasks/main.yaml +++ b/tests/integration/targets/uv_python/tasks/main.yaml @@ -257,10 +257,25 @@ - name: No specified version uv_python: state: latest + version: "" ignore_errors: true register: no_version - name: Verify failure when no version is specified assert: that: - - no_version.failed is true \ No newline at end of file + - no_version.failed is true + - '"Unsupported version format" in no_version.msg' + +- name: Unsupported version format given + uv_python: + state: latest + version: "3.8.post2" + ignore_errors: true + register: wrong_version + +- name: Verify failure when unsupported version format is specified + assert: + that: + - wrong_version.failed is true + - '"Unsupported version format" in wrong_version.msg' \ No newline at end of file