Project

General

Profile

Actions

Bug #21829

closed

Specifying wrong foreign key id for object (such as host or hostgroup) via hammer/api throws SQL error

Added by Andrew Kofink over 6 years ago. Updated over 5 years ago.

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

Description

Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1488475

Description of problem:
If you specify non-existent (i.e.) 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):
Foreman 1.16

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:


Related issues 3 (2 open1 closed)

Blocks Foreman - Bug #23208: Validate existing FK relationshipsNew04/10/2018Actions
Blocks Katello - Bug #23209: Validate existing FK relationshipsNew04/10/2018Actions
Copied from Katello - Bug #21689: Specifying wrong foreign key id for object (such as host or hostgroup) via hammer/api throws SQL errorClosedAndrew Kofink11/16/2017Actions
Actions #1

Updated by Andrew Kofink over 6 years ago

  • Copied from Bug #21689: Specifying wrong foreign key id for object (such as host or hostgroup) via hammer/api throws SQL error added
Actions #2

Updated by The Foreman Bot almost 6 years ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/5405 added
Actions #3

Updated by Lukas Zapletal almost 6 years ago

  • translation missing: en.field_release set to 330
Actions #4

Updated by Anonymous almost 6 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100
Actions #5

Updated by Andrew Kofink almost 6 years ago

  • Blocks Bug #23208: Validate existing FK relationships added
Actions #6

Updated by Andrew Kofink almost 6 years ago

  • Blocks Bug #23209: Validate existing FK relationships added
Actions

Also available in: Atom PDF