Project

General

Profile

Bug #21829

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

Added by Andrew Kofink about 1 year ago. Updated 5 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
-
Target version:
Difficulty:
Triaged:
Bugzilla link:
Team Backlog:
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

Blocks Foreman - Bug #23208: Validate existing FK relationshipsNew2018-04-10
Blocks Katello - Bug #23209: Validate existing FK relationshipsNew2018-04-10
Copied from Katello - Bug #21689: Specifying wrong foreign key id for object (such as host or hostgroup) via hammer/api throws SQL errorClosed2017-11-16

Associated revisions

Revision 8efbe7d1 (diff)
Added by Andrew Kofink 8 months ago

Fixes #21829: Add association_exists_validator (#5405)

This validator ensures that an associated model (fk relation) actually
exists with the ID specified on this model. i.e. Hostgroup.realm_id

This PR is required for Katello to require a ContentFacet on a Host.

History

#1 Updated by Andrew Kofink about 1 year ago

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

#2 Updated by The Foreman Bot 8 months ago

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

#3 Updated by Lukas Zapletal 8 months ago

  • Legacy Backlogs Release (now unused) set to 330

#4 Updated by Anonymous 8 months ago

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

#5 Updated by Andrew Kofink 8 months ago

  • Blocks Bug #23208: Validate existing FK relationships added

#6 Updated by Andrew Kofink 8 months ago

  • Blocks Bug #23209: Validate existing FK relationships added

Also available in: Atom PDF