Bug #35338
openUsing input() in a host parameters leads to `template_inputs' for nil:NilClass on hosts overview error
Description
When i create a Host Parameter of type string containing a call to the input
erb method, I can save the host settings but the host overview will break.
To reproduce, create a variable called test
with the contents <% input('test') %>
next navigate to the hosts view and you get "undefined method `template_inputs' for nil:NilClass"
The value is stored in the db, and the only way to recover the hosts page is to fix it in the database where it is stored:
# select name,value from parameters where name = 'test'; name | value ------+--------------------------- test | --- "<% input('test') %>"+ | (1 row) # update parameters set value = '' where name = 'test'; UPDATE 1
The attached stack-trace doesn't completely match #35095 but i it to be related to this issue because it's throwing the same error.
My gut feeling is that this was introduced in https://github.com/theforeman/foreman/commit/989e0aad01df80dea8fd4734a78e794770b39f2d but that was already in 3.1.0 which wouldn't add up with my feeling that this might be related to #35095.
The root exception seems to be triggered here: https://github.com/theforeman/foreman/blob/aef76932236377f18cfecd2100576dcda577e2bf/app/services/foreman/renderer/scope/macros/inputs.rb#L37
I stumbled over this when i was trying to manage job templates using the theforeman.foreman.job_template
module from FAM. I can probably find workarounds for my use-case but the fact that a wrong host variable can make the hosts list unusable feels like this warrants a bug report.
Files
Updated by Lucas Bickel over 2 years ago
- Subject changed from Using input() in a nested string fails in host parameters leads to `template_inputs' for nil:NilClass on hosts overview to Using input() in a host parameters leads to `template_inputs' for nil:NilClass on hosts overview error
Updated by Maria Agaphontzev over 2 years ago
I got the same error. I used foreman with no plugins, added this param to the host, went to host details (legacy page) -> templates tab -> preview template.
The error happened in a different function in the same file
https://github.com/theforeman/foreman/blob/aef76932236377f18cfecd2100576dcda577e2bf/app/services/foreman/renderer/scope/macros/inputs.rb#L21