Bug #17525
closedUser unfriendly foreign key exception when creating/updating a resource
Description
Sending a nonexistent id when creating or updating a resource via API ends up with a foreign key exception on foreman instances running on a postgres backend.
Reproducer using hammer:
hammer domain create --dns-id 3283 --name test.org Could not create the domain: ERROR: insert or update on table "domains" violates foreign key constraint "domains_dns_id_fk" DETAIL: Key (dns_id)=(3283) is not present in table "smart_proxies".
Relevant part of the server log:
2016-11-30T08:09:17 8a771c14 [app] [I] Started POST "/api/domains" for fe80::5054:ff:fef5:1b57 at 2016-11-30 08:09:17 +0000 2016-11-30T08:09:17 8a771c14 [app] [I] Processing by Api::V2::DomainsController#create as JSON 2016-11-30T08:09:17 8a771c14 [app] [I] Parameters: {"domain"=>{"name"=>"test.org", "dns_id"=>"3283"}, "apiv"=>"v2"} 2016-11-30T08:09:17 8a771c14 [app] [W] Action failed | PG::ForeignKeyViolation: ERROR: insert or update on table "domains" violates foreign key constraint "domains_dns_id_fk" | DETAIL: Key (dns_id)=(3283) is not present in table "smart_proxies". | ... 2016-11-30T08:09:17 8a771c14 [app] [I] Rendered api/v2/errors/standard_error.json.rabl within api/v2/layouts/error_layout (0.5ms) 2016-11-30T08:09:17 8a771c14 [app] [I] Completed 500 Internal Server Error in 19ms (Views: 1.9ms | ActiveRecord: 2.4ms)
The reproducer uses domains as a simple example, but the problem is present across all resources in the API.
Expected results:
The server should reply with a more user friendly message instead, for example:
Proxy (id: 3283) doesn't exist.
Additional INFO:
I haven't tested the behavior on different database backends.
Updated by Shlomi Zadok almost 8 years ago
- Assignee set to Shlomi Zadok
- Target version changed from 115 to 1.10.1
Updated by The Foreman Bot almost 8 years ago
- Status changed from New to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/4120 added
Updated by Shlomi Zadok almost 8 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset 8b3f1a97bf4844e55c040e2e156a0794c3e63f8f.
Updated by Dominic Cleal almost 8 years ago
- Translation missing: en.field_release set to 209
This has only changed the error message for the one specific example (domain with dns_id) given here.
Updated by The Foreman Bot over 7 years ago
- Pull request https://github.com/theforeman/foreman/pull/4677 added
Updated by Dominik Hlavac Duran over 7 years ago
- Status changed from Closed to Assigned
- Assignee changed from Shlomi Zadok to Dominik Hlavac Duran
- Target version changed from 1.10.1 to 115
Updated by Marek Hulán about 7 years ago
- Status changed from Assigned to Closed
Let's not reopen bugs aligned to specific releases. Please open a new issue for more generic solution.
Updated by Marek Hulán about 7 years ago
- Related to Bug #20888: creating a hostgroup with invalid id option should raise proper error instead of foreign key constraint error added