From 412a348738fdacc74f54f398de8d672f030d902e Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 27 Apr 2026 21:13:47 +0200 Subject: [PATCH] [PR #11918/89d82ab9 backport][stable-12] scaleway: fix NoneType error in get_resources() (#11924) scaleway: fix NoneType error in get_resources() (#11918) * scaleway: fix NoneType error in get_resources() when API returns empty or non-JSON response * add changelog fragment for #11918 * Update changelogs/fragments/11361-scaleway-get-resources-none-type.yml --------- (cherry picked from commit 89d82ab9dfe9eb5ecda7a47a11f10a7b4f4d6d7f) Co-authored-by: RealCharlesChia <161665317+RealCharlesChia@users.noreply.github.com> Co-authored-by: RealCharlesChia Co-authored-by: Felix Fontein --- .../fragments/11361-scaleway-get-resources-none-type.yml | 2 ++ plugins/module_utils/scaleway.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/11361-scaleway-get-resources-none-type.yml diff --git a/changelogs/fragments/11361-scaleway-get-resources-none-type.yml b/changelogs/fragments/11361-scaleway-get-resources-none-type.yml new file mode 100644 index 0000000000..b12d37deaa --- /dev/null +++ b/changelogs/fragments/11361-scaleway-get-resources-none-type.yml @@ -0,0 +1,2 @@ +bugfixes: + - scaleway_image_info, scaleway_ip_info, scaleway_organization_info, scaleway_security_group_info, scaleway_server_info, scaleway_snapshot_info, scaleway_volume_info - fix ``NoneType`` error when the Scaleway API returns an empty or non-JSON response body (https://github.com/ansible-collections/community.general/issues/11361, https://github.com/ansible-collections/community.general/pull/11918). \ No newline at end of file diff --git a/plugins/module_utils/scaleway.py b/plugins/module_utils/scaleway.py index ee09b2dd9c..914cc5db65 100644 --- a/plugins/module_utils/scaleway.py +++ b/plugins/module_utils/scaleway.py @@ -237,10 +237,15 @@ class Scaleway: results = self.get(f"/{self.name}") if not results.ok: + api_response = results.json if results.json is not None else results.body + message = api_response.get("message") if isinstance(api_response, dict) else api_response raise ScalewayException( - f"Error fetching {self.name} ({self.module.params.get('api_url')}/{self.name}) [{results.status_code}: {results.json['message']}]" + f"Error fetching {self.name} ({self.module.params.get('api_url')}/{self.name}) [{results.status_code}: {message}]" ) + if results.json is None: + raise ScalewayException(f"Scaleway API returned an empty or non-JSON response for {self.name}") + return results.json.get(self.name) def _url_builder(self, path, params):