Project

General

Profile

Actions

Bug #20888

closed

creating a hostgroup with invalid id option should raise proper error instead of foreign key constraint error

Added by Marek Hulán about 7 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Normal
Category:
API
Target version:
Difficulty:
Triaged:
Yes
Fixed in Releases:
Found in Releases:

Description

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

Description of problem:
Creating a hostgroup with invalid subnet id raises:

~]# hammer -u admin -p changeme hostgroup create --name test123512 --organizations='Default Organization' --location-ids 1 --puppet-proxy-id 1 --puppet-ca-proxy-id 1 --root-pass redhat123 --subnet-id 1 --domain-id 1
Could not create the hostgroup:
ERROR: insert or update on table "hostgroups" violates foreign key constraint "hostgroups_subnet_id_fk"
DETAIL: Key (subnet_id)=(1) is not present in table "subnets".

Version-Release number of selected component (if applicable):
all

How reproducible:
100%

Steps to Reproduce:
1. create hostgroup with invalid subnet-id

Actual results:

see 500

Expected results:
user should get an error: subnet not found

Additional info:

Currently we don't check ids before we try to use them in DB. When users pass invalid id via API call, they experience 500, following (or similar) can be found in logs

PG::ForeignKeyViolation: ERROR:  insert or update on table "domains" violates foreign key constraint "domains_dns_id_fk" 

While there were fixes on few places (#17525), this is a generic problem and we should fix it in all API endpoints. It would be good to have a DSL that would accept a model and permission, which would do the validation for a given combination, similarly like in the linked issue. Then we should fix the issue with hostgroup-subnet_id with it.


Related issues 2 (1 open1 closed)

Related to Foreman - Bug #17525: User unfriendly foreign key exception when creating/updating a resourceClosedDominik Hlavac Duran11/30/2016Actions
Related to Foreman - Bug #25006: creating a hostgroup with invalid id option should raise proper error instead of foreign key constraint errorReady For TestingAmit KarsaleActions
Actions #1

Updated by Marek Hulán about 7 years ago

  • Subject changed from creating a hostgroup with invalid id option should raise proper error instead of foreign key constraint error to creating a hostgroup with invalid id option should raise proper error instead of foreign key constraint error
  • Category changed from Host groups to API
Actions #2

Updated by Marek Hulán about 7 years ago

  • Related to Bug #17525: User unfriendly foreign key exception when creating/updating a resource added
Actions #3

Updated by Amit Karsale over 6 years ago

Other dependent BZ : 1484102 (w.r.t invalid --operatinsystem-id attribute)

Actions #4

Updated by Amit Karsale over 6 years ago

  • Project changed from Foreman to Katello
  • Category changed from API to API
Actions #5

Updated by The Foreman Bot over 6 years ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/Katello/katello/pull/7631 added
Actions #6

Updated by The Foreman Bot over 6 years ago

  • Pull request https://github.com/Katello/katello/pull/7633 added
Actions #7

Updated by Amit Karsale over 6 years ago

  • Pull request deleted (https://github.com/Katello/katello/pull/7631)
Actions #8

Updated by Andrew Kofink over 6 years ago

  • Target version set to Katello 3.9.0
  • Triaged changed from No to Yes
Actions #9

Updated by Amit Karsale about 6 years ago

  • Related to Bug #25006: creating a hostgroup with invalid id option should raise proper error instead of foreign key constraint error added
Actions #10

Updated by Zach Huntington-Meath about 6 years ago

  • Target version changed from Katello 3.9.0 to Katello 3.11.0
Actions #11

Updated by John Mitsch almost 6 years ago

  • Target version changed from Katello 3.11.0 to Katello 3.12.0
Actions #12

Updated by Chris Roberts over 5 years ago

  • Target version changed from Katello 3.12.0 to Katello 3.13.0
  • Triaged changed from Yes to No
Actions #13

Updated by Andrew Kofink over 5 years ago

  • Triaged changed from No to Yes
Actions #14

Updated by Jonathon Turel over 5 years ago

  • Target version changed from Katello 3.13.0 to Katello 3.14.0
Actions #15

Updated by Jonathon Turel almost 5 years ago

  • Target version changed from Katello 3.14.0 to Katello 3.15.0
Actions #16

Updated by James Jeffers almost 5 years ago

  • Status changed from Ready For Testing to Closed
  • Target version changed from Katello 3.15.0 to Katello Recycle Bin
Actions

Also available in: Atom PDF