From 171feb5a2cf9a23ba0b5cb2fcc6d37261e98169e Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Tue, 12 May 2026 20:59:14 +1200 Subject: [PATCH] datadog_downtime: handle uuid.UUID type in API response (#12019) * fix(datadog_downtime): convert uuid field to str for datadog-api-client>=2.28.0 Co-Authored-By: Claude Sonnet 4.6 * changelog: add fragment for PR 12019 Co-Authored-By: Claude Sonnet 4.6 --------- Co-authored-by: Claude Sonnet 4.6 --- .../fragments/12019-datadog-downtime-uuid.yml | 4 ++++ plugins/modules/datadog_downtime.py | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/12019-datadog-downtime-uuid.yml diff --git a/changelogs/fragments/12019-datadog-downtime-uuid.yml b/changelogs/fragments/12019-datadog-downtime-uuid.yml new file mode 100644 index 0000000000..58a46bf142 --- /dev/null +++ b/changelogs/fragments/12019-datadog-downtime-uuid.yml @@ -0,0 +1,4 @@ +bugfixes: + - "datadog_downtime - fix ``TypeError`` when returning API response with ``datadog-api-client`` >= 2.28.0 + (https://github.com/ansible-collections/community.general/issues/9079, + https://github.com/ansible-collections/community.general/pull/12019)." diff --git a/plugins/modules/datadog_downtime.py b/plugins/modules/datadog_downtime.py index 3afbc1d1d8..58505e2ab6 100644 --- a/plugins/modules/datadog_downtime.py +++ b/plugins/modules/datadog_downtime.py @@ -247,13 +247,20 @@ def build_downtime(module): return downtime +def _resp_to_dict(resp): + d = resp.to_dict() + if "uuid" in d: + d["uuid"] = str(d["uuid"]) + return d + + def _post_downtime(module, api_client): api = DowntimesApi(api_client) downtime = build_downtime(module) try: resp = api.create_downtime(downtime) module.params["id"] = resp.id - module.exit_json(changed=True, downtime=resp.to_dict()) + module.exit_json(changed=True, downtime=_resp_to_dict(resp)) except ApiException as e: module.fail_json(msg=f"Failed to create downtime: {e}") @@ -273,9 +280,9 @@ def _update_downtime(module, current_downtime, api_client): else: resp = api.update_downtime(module.params["id"], downtime) if _equal_dicts(resp.to_dict(), current_downtime.to_dict(), ["active", "creator_id", "updater_id"]): - module.exit_json(changed=False, downtime=resp.to_dict()) + module.exit_json(changed=False, downtime=_resp_to_dict(resp)) else: - module.exit_json(changed=True, downtime=resp.to_dict()) + module.exit_json(changed=True, downtime=_resp_to_dict(resp)) except ApiException as e: module.fail_json(msg=f"Failed to update downtime: {e}")