Project

General

Profile

Bug #35825

Payload crashes if object returns nil

Added by Jonas Trüstedt 4 months ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Difficulty:
Triaged:
No
Bugzilla link:
Pull request:
Fixed in Releases:
Found in Releases:
Red Hat JIRA:

Description

Using a template like:

<%=
payload({
id: @object.id,
name: @object.name,
organization: @object.organization.name,
ip: [ @object.ip, @object.ip6 ],
description: @object.comment,
hostgroup: @object.hostgroup
})
-%>

The webhook/payload-function crashes if the host targeted has no hostgroup with a message that it cannot 'render' for nil:NilClass.
You can workaround that by casting that into a string with:

hostgroup: @object.hostgroup.to_s

But in that case if the hostgroup is not set it will just return an empty string and something like "null" would be better.

Version used is Foreman 3.1 with Webhooks-Plugin 3.0

Also available in: Atom PDF