Bug #21689
closedSpecifying wrong foreign key id for object (such as host or hostgroup) via hammer/api throws SQL error
Description
Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1488475
Description of problem:
If you specify non-existent content source id for hammer host/hostgroup create/update command, SQL error is shown instead of validation message.
Version-Release number of selected component (if applicable):
Satellite 6.3.0 Snap 14
How reproducible:
Always
Steps to Reproduce:
1. Execute host/hostgroup create/update command with --content-source-id set to some nonexistent id:
hammer host create --medium-id="169" --ip="###.###.##.###" --location-id="2" --operatingsystem-id="3" --lifecycle-environment-id="593" --domain-id="1" --partition-table-id="87" --content-source-id="61340" --mac="40:8f:bf:b6:ca:7a" --content-view-id="618" --architecture-id="1" --organization="RshekR" --name="mYXwuGUHRd" --root-password="test"
2.
3.
Actual results:
[ERROR 2017-09-05 09:04:15 API] 500 Internal Server Error
[ERROR 2017-09-05 09:04:15 Exception] ERROR: insert or update on table "katello_content_facets" violates foreign key constraint "katello_content_facets_content_source_id_fk"
DETAIL: Key (content_source_id)=(61340) is not present in table "smart_proxies".
Could not create the host:
ERROR: insert or update on table "katello_content_facets" violates foreign key constraint "katello_content_facets_content_source_id_fk"
DETAIL: Key (content_source_id)=(61340) is not present in table "smart_proxies".
[ERROR 2017-09-05 09:04:15 Exception]
RestClient::InternalServerError (500 Internal Server Error):
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-1.8.0/lib/restclient/abstract_response.rb:74:in `return!'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.0/lib/apipie_bindings/api.rb:352:in `block in rest_client_call_block'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-1.8.0/lib/restclient/request.rb:493:in `process_result'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-1.8.0/lib/restclient/request.rb:421:in `block in transmit'
/opt/rh/rh-ruby23/root/usr/share/ruby/net/http.rb:853:in `start'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-1.8.0/lib/restclient/request.rb:413:in `transmit'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-1.8.0/lib/restclient/request.rb:176:in `execute'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-1.8.0/lib/restclient/request.rb:41:in `execute'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-1.8.0/lib/restclient/resource.rb:67:in `post'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.0/lib/apipie_bindings/api.rb:324:in `call_client'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.0/lib/apipie_bindings/api.rb:240:in `http_call'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.0/lib/apipie_bindings/api.rb:190:in `call_action'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.0/lib/apipie_bindings/api.rb:185:in `call'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.0/lib/apipie_bindings/resource.rb:21:in `call'
/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.10.2/lib/hammer_cli/apipie/command.rb:43:in `send_request'
/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_foreman-0.10.2/lib/hammer_cli_foreman/commands.rb:166:in `send_request'
/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.10.2/lib/hammer_cli/apipie/command.rb:34:in `execute'
/opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/command.rb:68:in `run'
/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.10.2/lib/hammer_cli/abstract.rb:29:in `run'
/opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/subcommand/execution.rb:11:in `execute'
/opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/command.rb:68:in `run'
/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.10.2/lib/hammer_cli/abstract.rb:29:in `run'
/opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/subcommand/execution.rb:11:in `execute'
/opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/command.rb:68:in `run'
/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.10.2/lib/hammer_cli/abstract.rb:29:in `run'
/opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/command.rb:133:in `run'
/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.10.2/bin/hammer:147:in `<top (required)>'
/usr/bin/hammer:23:in `load'
/usr/bin/hammer:23:in `<main>'
Expected results:
Some kind of validation message explaining that content source was not found by provided id should be shown.
Additional info:
Updated by The Foreman Bot about 7 years ago
- Status changed from New to Ready For Testing
- Assignee set to Andrew Kofink
- Pull request https://github.com/Katello/katello/pull/7075 added
Updated by Justin Sherrill about 7 years ago
- Subject changed from Specifying wrong content source id for host or hostgroup via hammer throws SQL error to Specifying wrong foreign key id for object (such as host or hostgroup) via hammer/api throws SQL error
- Translation missing: en.field_release set to 114
Updated by Justin Sherrill about 7 years ago
Foreman-only examples:
- hammer -p changeme hostgroup create --name=foobar123 --realm-id=99999
Could not create the hostgroup:
ERROR: insert or update on table "hostgroups" violates foreign key constraint "hostgroups_realms_id_fk"
DETAIL: Key (realm_id)=(99999) is not present in table "realms".
- hammer -p changeme hostgroup create --name=foobar123 --operatingsystem-id=99999
Could not create the hostgroup:
ERROR: insert or update on table "hostgroups" violates foreign key constraint "hostgroups_operatingsystem_id_fk"
DETAIL: Key (operatingsystem_id)=(99999) is not present in table "operatingsystems".
Updated by Andrew Kofink about 7 years ago
- Status changed from Ready For Testing to Assigned
- Pull request deleted (
https://github.com/Katello/katello/pull/7075)
Updated by Andrew Kofink about 7 years ago
- Copied to Bug #21829: Specifying wrong foreign key id for object (such as host or hostgroup) via hammer/api throws SQL error added
Updated by The Foreman Bot over 6 years ago
- Status changed from Assigned to Ready For Testing
- Translation missing: en.field_release deleted (
114) - Pull request https://github.com/Katello/katello/pull/7287 added
Updated by Andrew Kofink over 6 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset katello|18eb35587087fc5a67edeb4725ac322a015a3f42.
Updated by Justin Sherrill over 6 years ago
- Translation missing: en.field_release set to 338
Updated by Andrew Kofink over 6 years ago
- Related to Bug #24559: Hostgroups should use AssociationExistsValidator for content_source added