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}")