Project

General

Profile

Actions

Bug #7855

open

UI HostGroup fails to render after REST API call

Added by Stephen Hayward over 9 years ago. Updated about 9 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Parameters
Target version:
-
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

To reproduce
- Use the REST API (v2) to override a String Array value, supplying an empty array as the value ([])
- Navigate to the Host Group page and select the Host Group which has the overridden parameter
- UI will show an error

JSON::GeneratorError
only generation of JSON objects or arrays allowed
app/models/lookup_key.rb:124:in `value_before_type_cast'
app/models/lookup_value.rb:29:in `value_before_type_cast'
app/views/common_parameters/_puppetclass_parameter.html.erb:14:in `_app_views_common_parameters__puppetclass_parameter_html_erb___1259980600488854889_87301500'
app/views/common_parameters/_puppetclasses_parameters.html.erb:3:in `block in app_views_common_parameters_puppetclasses_parameters_html_erb__2588621181520589588_86961740'
app/views/common_parameters/_puppetclasses_parameters.html.erb:2:in `_app_views_common_parameters__puppetclasses_parameters_html_erb__2588621181520589588_86961740'
app/views/hostgroups/_form.html.erb:63:in `block in app_views_hostgroups_form_html_erb__1140218788628501782_77616660'
app/helpers/layout_helper.rb:250:in `form_for'
app/views/hostgroups/_form.html.erb:2:in `_app_views_hostgroups__form_html_erb__1140218788628501782_77616660'
app/views/hostgroups/edit.html.erb:3:in `_app_views_hostgroups_edit_html_erb__2077798922353845900_77452900'
app/models/concerns/foreman/thread_session.rb:33:in `clear_thread'
lib/middleware/catch_json_parse_errors.rb:9:in `call'

The REST call from my client looks like this.

14947 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection - Sending request: POST /api/v2/smart_class_parameters/640/override_values HTTP/1.1
14947 [main] DEBUG org.apache.http.wire - >> "POST /api/v2/smart_class_parameters/640/override_values HTTP/1.1[\r][\n]"
14948 [main] DEBUG org.apache.http.wire - >> "Accept-Encoding: gzip, deflate[\r][\n]"
14948 [main] DEBUG org.apache.http.wire - >> "Authorization: Basic YWRtaW46Y2hhbmdlbWU=[\r][\n]"
14948 [main] DEBUG org.apache.http.wire - >> "Content-Type: application/json[\r][\n]"
14948 [main] DEBUG org.apache.http.wire - >> "Content-Length: 66[\r][\n]"
14948 [main] DEBUG org.apache.http.wire - >> "Host: 10.11.164.20[\r][\n]"
14948 [main] DEBUG org.apache.http.wire - >> "Connection: Keep-Alive[\r][\n]"
14948 [main] DEBUG org.apache.http.wire - >> "User-Agent: Apache-HttpClient/4.2.1 (java 1.5)[\r][\n]"
14948 [main] DEBUG org.apache.http.wire - >> "Cookie: _session_id=7414ecbd7f94b341cc5ac933a478c3de[\r][\n]"
14949 [main] DEBUG org.apache.http.wire - >> "Cookie2: $Version=1[\r][\n]"
14949 [main] DEBUG org.apache.http.wire - >> "[\r][\n]"
14949 [main] DEBUG org.apache.http.headers - >> POST /api/v2/smart_class_parameters/640/override_values HTTP/1.1
14949 [main] DEBUG org.apache.http.headers - >> Accept-Encoding: gzip, deflate
14949 [main] DEBUG org.apache.http.headers - >> Authorization: Basic YWRtaW46Y2hhbmdlbWU=
14949 [main] DEBUG org.apache.http.headers - >> Content-Type: application/json
14949 [main] DEBUG org.apache.http.headers - >> Content-Length: 66
14949 [main] DEBUG org.apache.http.headers - >> Host: 10.11.164.20
14949 [main] DEBUG org.apache.http.headers - >> Connection: Keep-Alive
14949 [main] DEBUG org.apache.http.headers - >> User-Agent: Apache-HttpClient/4.2.1 (java 1.5)
14949 [main] DEBUG org.apache.http.headers - >> Cookie: _session_id=7414ecbd7f94b341cc5ac933a478c3de
14949 [main] DEBUG org.apache.http.headers - >> Cookie2: $Version=1
14950 [main] DEBUG org.apache.http.wire - >> "{"override_value": {"match": "hostgroup=SDPCloned" ,"value" : []}}"
15132 [main] DEBUG org.apache.http.wire - << "HTTP/1.1 200 OK[\r][\n]"
15132 [main] DEBUG org.apache.http.wire - << "Date: Wed, 08 Oct 2014 14:00:02 GMT[\r][\n]"
15132 [main] DEBUG org.apache.http.wire - << "Server: Apache/2.2.15 (Red Hat)[\r][\n]"
15132 [main] DEBUG org.apache.http.wire - << "Foreman_version: 1.5.1[\r][\n]"
15132 [main] DEBUG org.apache.http.wire - << "Foreman_api_version: 2[\r][\n]"
15133 [main] DEBUG org.apache.http.wire - << "Apipie-Checksum: 415cd199100d21dbbcabd10286c721db[\r][\n]"
15133 [main] DEBUG org.apache.http.wire - << "X-UA-Compatible: IE=Edge,chrome=1[\r][\n]"
15133 [main] DEBUG org.apache.http.wire - << "ETag: "99874959cc9011d2f932ee8f31c5b152"[\r][\n]"
15133 [main] DEBUG org.apache.http.wire - << "Cache-Control: max-age=0, private, must-revalidate[\r][\n]"
15133 [main] DEBUG org.apache.http.wire - << "X-Request-Id: 70903e26ee7599932087eb165f4647a1[\r][\n]"
15133 [main] DEBUG org.apache.http.wire - << "X-Runtime: 0.177317[\r][\n]"
15133 [main] DEBUG org.apache.http.wire - << "X-Rack-Cache: invalidate, pass[\r][\n]"
15133 [main] DEBUG org.apache.http.wire - << "X-Powered-By: Phusion Passenger 4.0.18[\r][\n]"
15133 [main] DEBUG org.apache.http.wire - << "Status: 200 OK[\r][\n]"
15133 [main] DEBUG org.apache.http.wire - << "Connection: close[\r][\n]"
15134 [main] DEBUG org.apache.http.wire - << "Transfer-Encoding: chunked[\r][\n]"
15134 [main] DEBUG org.apache.http.wire - << "Content-Type: application/json; charset=utf-8[\r][\n]"
15134 [main] DEBUG org.apache.http.wire - << "[\r][\n]"
15134 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection - Receiving response: HTTP/1.1 200 OK
15134 [main] DEBUG org.apache.http.headers - << HTTP/1.1 200 OK
15134 [main] DEBUG org.apache.http.headers - << Date: Wed, 08 Oct 2014 14:00:02 GMT
15134 [main] DEBUG org.apache.http.headers - << Server: Apache/2.2.15 (Red Hat)
15134 [main] DEBUG org.apache.http.headers - << Foreman_version: 1.5.1
15134 [main] DEBUG org.apache.http.headers - << Foreman_api_version: 2
15134 [main] DEBUG org.apache.http.headers - << Apipie-Checksum: 415cd199100d21dbbcabd10286c721db
15134 [main] DEBUG org.apache.http.headers - << X-UA-Compatible: IE=Edge,chrome=1
15134 [main] DEBUG org.apache.http.headers - << ETag: "99874959cc9011d2f932ee8f31c5b152"
15134 [main] DEBUG org.apache.http.headers - << Cache-Control: max-age=0, private, must-revalidate
15134 [main] DEBUG org.apache.http.headers - << X-Request-Id: 70903e26ee7599932087eb165f4647a1
15135 [main] DEBUG org.apache.http.headers - << X-Runtime: 0.177317
15135 [main] DEBUG org.apache.http.headers - << X-Rack-Cache: invalidate, pass
15135 [main] DEBUG org.apache.http.headers - << X-Powered-By: Phusion Passenger 4.0.18
15135 [main] DEBUG org.apache.http.headers - << Status: 200 OK
15135 [main] DEBUG org.apache.http.headers - << Connection: close
15135 [main] DEBUG org.apache.http.headers - << Transfer-Encoding: chunked
15135 [main] DEBUG org.apache.http.headers - << Content-Type: application/json; charset=utf-8
15139 [main] DEBUG org.apache.http.wire - << "7e[\r][\n]"
15139 [main] DEBUG org.apache.http.wire - << "{"id":7875,"match":"hostgroup=SDPCloned","value":null,"created_at":"2014-10-08T14:00:02Z","updated_at":"2014-10-08T14:00:02Z"}"
15139 [main] DEBUG org.apache.http.wire - << "[\r][\n]"
15140 [main] DEBUG org.apache.http.wire - << "0[\r][\n]"
15140 [main] DEBUG org.apache.http.wire - << "[\r][\n]"

I have attached the foreman debug log


Files

foreman-debug-JYCsh.tar.xz foreman-debug-JYCsh.tar.xz 127 KB Stephen Hayward, 10/08/2014 10:24 AM
Actions #1

Updated by Stephen Hayward over 9 years ago

The code works for all other non-empty array values

Actions #2

Updated by Dominic Cleal over 9 years ago

  • Category set to Parameters

It might you need to supply the override value as a string, e.g. value: "[]" because Foreman won't be expecting raw objects over the wire (which are encoded in JSON), it's expecting the user to enter JSON as a string in the web UI - and probably the same in the API.

Actions #3

Updated by Stephen Hayward over 9 years ago

Dominic Cleal wrote:

It might you need to supply the override value as a string, e.g. value: "[]" because Foreman won't be expecting raw objects over the wire (which are encoded in JSON), it's expecting the user to enter JSON as a string in the web UI - and probably the same in the API.

Ok but if I supply values then it works correctly

[main] DEBUG org.apache.http.impl.conn.DefaultClientConnection - Sending request: POST /api/v2/smart_class_parameters/640/override_values HTTP/1.1
15134 [main] DEBUG org.apache.http.wire - >> "POST /api/v2/smart_class_parameters/640/override_values HTTP/1.1[\r][\n]"
15134 [main] DEBUG org.apache.http.wire - >> "Accept-Encoding: gzip, deflate[\r][\n]"
15134 [main] DEBUG org.apache.http.wire - >> "Authorization: Basic YWRtaW46Y2hhbmdlbWU=[\r][\n]"
15134 [main] DEBUG org.apache.http.wire - >> "Content-Type: application/json[\r][\n]"
15134 [main] DEBUG org.apache.http.wire - >> "Content-Length: 73[\r][\n]"
15134 [main] DEBUG org.apache.http.wire - >> "Host: 10.11.164.20[\r][\n]"
15134 [main] DEBUG org.apache.http.wire - >> "Connection: Keep-Alive[\r][\n]"
15134 [main] DEBUG org.apache.http.wire - >> "User-Agent: Apache-HttpClient/4.2.1 (java 1.5)[\r][\n]"
15134 [main] DEBUG org.apache.http.wire - >> "Cookie: _session_id=6eae22cec6096b63ab0bb329eefaa42a[\r][\n]"
15135 [main] DEBUG org.apache.http.wire - >> "Cookie2: $Version=1[\r][\n]"
15135 [main] DEBUG org.apache.http.wire - >> "[\r][\n]"
15135 [main] DEBUG org.apache.http.headers - >> POST /api/v2/smart_class_parameters/640/override_values HTTP/1.1
15135 [main] DEBUG org.apache.http.headers - >> Accept-Encoding: gzip, deflate
15135 [main] DEBUG org.apache.http.headers - >> Authorization: Basic YWRtaW46Y2hhbmdlbWU=
15135 [main] DEBUG org.apache.http.headers - >> Content-Type: application/json
15135 [main] DEBUG org.apache.http.headers - >> Content-Length: 73
15135 [main] DEBUG org.apache.http.headers - >> Host: 10.11.164.20
15135 [main] DEBUG org.apache.http.headers - >> Connection: Keep-Alive
15135 [main] DEBUG org.apache.http.headers - >> User-Agent: Apache-HttpClient/4.2.1 (java 1.5)
15135 [main] DEBUG org.apache.http.headers - >> Cookie: _session_id=6eae22cec6096b63ab0bb329eefaa42a
15135 [main] DEBUG org.apache.http.headers - >> Cookie2: $Version=1
15136 [main] DEBUG org.apache.http.wire - >> "{"override_value": {"match": "hostgroup=SDPCloned" ,"value" : ["a","b"]}}"
15356 [main] DEBUG org.apache.http.wire - << "HTTP/1.1 200 OK[\r][\n]"
15357 [main] DEBUG org.apache.http.wire - << "Date: Wed, 08 Oct 2014 14:37:53 GMT[\r][\n]"
15357 [main] DEBUG org.apache.http.wire - << "Server: Apache/2.2.15 (Red Hat)[\r][\n]"
15357 [main] DEBUG org.apache.http.wire - << "Foreman_version: 1.5.1[\r][\n]"
15357 [main] DEBUG org.apache.http.wire - << "Foreman_api_version: 2[\r][\n]"
15357 [main] DEBUG org.apache.http.wire - << "Apipie-Checksum: 415cd199100d21dbbcabd10286c721db[\r][\n]"
15357 [main] DEBUG org.apache.http.wire - << "X-UA-Compatible: IE=Edge,chrome=1[\r][\n]"
15357 [main] DEBUG org.apache.http.wire - << "ETag: "4e5a05d24fb6fd53343774e5f999cacf"[\r][\n]"
15357 [main] DEBUG org.apache.http.wire - << "Cache-Control: max-age=0, private, must-revalidate[\r][\n]"
15357 [main] DEBUG org.apache.http.wire - << "X-Request-Id: fb97a04418ed95f0e11040d9e32eefbd[\r][\n]"
15357 [main] DEBUG org.apache.http.wire - << "X-Runtime: 0.216103[\r][\n]"
15357 [main] DEBUG org.apache.http.wire - << "X-Rack-Cache: invalidate, pass[\r][\n]"
15357 [main] DEBUG org.apache.http.wire - << "X-Powered-By: Phusion Passenger 4.0.18[\r][\n]"
15357 [main] DEBUG org.apache.http.wire - << "Status: 200 OK[\r][\n]"
15357 [main] DEBUG org.apache.http.wire - << "Connection: close[\r][\n]"
15357 [main] DEBUG org.apache.http.wire - << "Transfer-Encoding: chunked[\r][\n]"
15357 [main] DEBUG org.apache.http.wire - << "Content-Type: application/json; charset=utf-8[\r][\n]"
15357 [main] DEBUG org.apache.http.wire - << "[\r][\n]"
15357 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection - Receiving response: HTTP/1.1 200 OK
15357 [main] DEBUG org.apache.http.headers - << HTTP/1.1 200 OK
15358 [main] DEBUG org.apache.http.headers - << Date: Wed, 08 Oct 2014 14:37:53 GMT
15358 [main] DEBUG org.apache.http.headers - << Server: Apache/2.2.15 (Red Hat)
15358 [main] DEBUG org.apache.http.headers - << Foreman_version: 1.5.1
15358 [main] DEBUG org.apache.http.headers - << Foreman_api_version: 2
15358 [main] DEBUG org.apache.http.headers - << Apipie-Checksum: 415cd199100d21dbbcabd10286c721db
15358 [main] DEBUG org.apache.http.headers - << X-UA-Compatible: IE=Edge,chrome=1
15358 [main] DEBUG org.apache.http.headers - << ETag: "4e5a05d24fb6fd53343774e5f999cacf"
15358 [main] DEBUG org.apache.http.headers - << Cache-Control: max-age=0, private, must-revalidate
15358 [main] DEBUG org.apache.http.headers - << X-Request-Id: fb97a04418ed95f0e11040d9e32eefbd
15358 [main] DEBUG org.apache.http.headers - << X-Runtime: 0.216103
15358 [main] DEBUG org.apache.http.headers - << X-Rack-Cache: invalidate, pass
15358 [main] DEBUG org.apache.http.headers - << X-Powered-By: Phusion Passenger 4.0.18
15358 [main] DEBUG org.apache.http.headers - << Status: 200 OK
15358 [main] DEBUG org.apache.http.headers - << Connection: close
15358 [main] DEBUG org.apache.http.headers - << Transfer-Encoding: chunked
15358 [main] DEBUG org.apache.http.headers - << Content-Type: application/json; charset=utf-8
15360 [main] DEBUG org.apache.http.wire - << "83[\r][\n]"
15360 [main] DEBUG org.apache.http.wire - << "{"id":7876,"match":"hostgroup=SDPCloned","value":["a","b"],"created_at":"2014-10-08T14:37:53Z","updated_at":"2014-10-08T14:37:53Z"}"
15361 [main] DEBUG org.apache.http.wire - << "[\r][\n]"
15361 [main] DEBUG org.apache.http.wire - << "0[\r][\n]"
15361 [main] DEBUG org.apache.http.wire - << "[\r][\n]"

Do I need to deal wih empt arrays in a different way ?

Actions #4

Updated by Stephen Hayward over 9 years ago

sorry that was meant to say "with empty array"

Actions

Also available in: Atom PDF