Project

General

Profile

Actions

Bug #17525

closed

User unfriendly foreign key exception when creating/updating a resource

Added by Tomáš Strachota almost 8 years ago. Updated over 6 years ago.

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

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.


Related issues 1 (0 open1 closed)

Related to Katello - Bug #20888: creating a hostgroup with invalid id option should raise proper error instead of foreign key constraint errorClosedDominik Hlavac DuranActions
Actions #1

Updated by Shlomi Zadok almost 8 years ago

  • Assignee set to Shlomi Zadok
  • Target version changed from 115 to 1.10.1
Actions #2

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
Actions #3

Updated by Shlomi Zadok almost 8 years ago

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

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.

Actions #5

Updated by The Foreman Bot over 7 years ago

  • Pull request https://github.com/theforeman/foreman/pull/4677 added
Actions #6

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
Actions #7

Updated by Marek Hulán over 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.

Actions #8

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
Actions

Also available in: Atom PDF