Project

General

Profile

Bug #17525

User unfriendly foreign key exception when creating/updating a resource

Added by Tomáš Strachota almost 5 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Normal
Category:
API
Target version:
Difficulty:
Triaged:
Bugzilla link:

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

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

Associated revisions

Revision 8b3f1a97 (diff)
Added by Shlomi Zadok almost 5 years ago

Fixes #17525 - Add a friendly error message to invalid dns_id

Revision 5a144e4b (diff)
Added by Marek Hulán about 4 years ago

Refs #17525 - verify domain dns id also on update

Revision d2eece63 (diff)
Added by Marek Hulán about 4 years ago

Refs #17525 - verify domain dns id also on update

(cherry picked from commit 5a144e4bf516db2dff4ffb798ebeca19eccd624f)

History

#1 Updated by Shlomi Zadok almost 5 years ago

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

#2 Updated by The Foreman Bot almost 5 years ago

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

#3 Updated by Shlomi Zadok almost 5 years ago

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

#4 Updated by Dominic Cleal almost 5 years ago

  • Legacy Backlogs Release (now unused) set to 209

This has only changed the error message for the one specific example (domain with dns_id) given here.

#5 Updated by The Foreman Bot about 4 years ago

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

#6 Updated by Dominik Hlavac Duran about 4 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

#7 Updated by Marek Hulán about 4 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.

#8 Updated by Marek Hulán about 4 years ago

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

Also available in: Atom PDF