Bug #20888
closedcreating a hostgroup with invalid id option should raise proper error instead of foreign key constraint error
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.
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
Updated by Marek Hulán about 7 years ago
- Related to Bug #17525: User unfriendly foreign key exception when creating/updating a resource added
Updated by Amit Karsale over 6 years ago
Other dependent BZ : 1484102 (w.r.t invalid --operatinsystem-id attribute)
Updated by Amit Karsale over 6 years ago
- Project changed from Foreman to Katello
- Category changed from API to API
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
Updated by The Foreman Bot over 6 years ago
- Pull request https://github.com/Katello/katello/pull/7633 added
Updated by Amit Karsale over 6 years ago
- Pull request deleted (
https://github.com/Katello/katello/pull/7631)
Updated by Andrew Kofink over 6 years ago
- Target version set to Katello 3.9.0
- Triaged changed from No to Yes
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
Updated by Zach Huntington-Meath about 6 years ago
- Target version changed from Katello 3.9.0 to Katello 3.11.0
Updated by John Mitsch almost 6 years ago
- Target version changed from Katello 3.11.0 to Katello 3.12.0
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
Updated by Jonathon Turel over 5 years ago
- Target version changed from Katello 3.13.0 to Katello 3.14.0
Updated by Jonathon Turel almost 5 years ago
- Target version changed from Katello 3.14.0 to Katello 3.15.0
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