Description of problem: API sometimes gives Ruby error "undefined method `id' for nil:NilClass" HTTP 500 error is more useful in this context. Version-Release number of selected component (if applicable): Version Satellite 6.2.6 Steps to Reproduce: [root@rhel7-3-server ~]# curl -H "Accept:application/json,version=2" -H "Content-Type:application/json" -X POST -u admin:password -k -d '{"architecture_id":"1","environment_name":"production", "domain_id":1, "mac":"00-00-5E-00-53-00", "location_id":1, "name":"test", "operatingsystem_id":"1","organization_id":"1" }' https://sat6-2.example.com/api/hosts | python -m json.tool % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 247 0 68 100 179 574 1513 --:--:-- --:--:-- --:--:-- 1516 { "error": { "message": "undefined method `id' for nil:NilClass" } } Actual results: "error": { "message": "undefined method `id' for nil:NilClass" Expected results: HTTP 500 Internal Error Additional info:
Hello Stephen, could you please also upload the production.log from time when you run this API call? This is generic error message which happens if there's bug in code so I'd like to know what was the cause. Anyway I agree we should print nicer error suggesting to look at production.log maybe.
Created attachment 1260413 [details] Production Log Hello I am sorry for delay. I could not find log from that long ago but managed to reproduce it. Here is new log. I ran the command directly in the Satellite VM, not a remote VM, hope that is OK.
Created redmine issue http://projects.theforeman.org/issues/18892 from this bug
Upstream bug assigned to oprazak
For the record, the original issue has been fixed by https://bugzilla.redhat.com/show_bug.cgi?id=1379006, the message now would look like following {"message":"Location with id 1 not found"} In your example you used the same id for location and organization which is obviously wrong. As a fix for this BZ, Ondra worked on a patch so that the message is different if similar issue happened again.
Ondra's PR mentioned in comment 10 was merged in upstream. It's scheduled to be part of 1.16.
Moving this bug to POST for triage into Satellite 6 since the upstream issue http://projects.theforeman.org/issues/18892 has been resolved.
I understand this BZ as "when there is ISE, API call should actually return 500 ISE". So I tried to cause ISE in the similar place as in the original traceback, adding "dummy = values_for_primary_interface.id" to 'def initialize' block after 'values_for_primary_interface = {}' in /usr/share/foreman/app/models/host/base.rb. Then: # curl -v -H "Accept:application/json,version=2" -H "Content-Type:application/json" -X POST -u admin:password -k https://$(hostname)/api/hosts [...] < Status: 500 Internal Server Error [...] { "error": {"message":"Internal Server Error: the server was unable to finish the request. This may be caused by unavailability of some required service, incorrect API call or a server-side bug. There may be more information in the server's logs."} } Status is 500 ISE, error message is on output -> verified with Sat 6.4 snap 8.
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHSA-2018:2927