Bug #4731

Creating domain when organization selected produces duplicate key error

Added by Ivan Necas over 3 years ago. Updated over 3 years ago.

Status:Closed
Priority:High
Assigned To:Joseph Magen
Category:Database
Target version:Sprint 22
Difficulty: Bugzilla link:1079999
Found in release: Pull request:
Story points-
Velocity based estimate-
Release1.5.0Release relationshipAuto

Description

1. choose organization
2. create new domain

Expected:

new domain created

Current:

Warning!

ERROR: duplicate key value violates unique constraint "domains_pkey" 

Notice:

When no org is selected, it works without issues


Related issues

Related to Foreman - Bug #4932: Creating Compute Resource results in DB error Duplicate 03/28/2014
Related to Foreman - Bug #16389: Can't create taxable e.g. domain object if I'm in context... Closed 08/31/2016
Duplicated by Foreman - Bug #4729: Importing subnet fails on unknown attribute Duplicate 03/19/2014

Associated revisions

Revision 3c4051e9
Added by Joseph Magen over 3 years ago

fixes #4731 - Rails 3.2.8 causing _pkey constraint errors

History

#1 Updated by Ivan Necas over 3 years ago

  • Description updated (diff)

#2 Updated by Ivan Necas over 3 years ago

  • Priority changed from Normal to High

Similar issue happens, when trying to create new provisioning template inside an org:

ERROR: duplicate key value violates unique constraint "config_templates_pkey" 

#3 Updated by Dominic Cleal over 3 years ago

  • Category set to Database

Occurs on PostgreSQL, not SQLite.

It looks like the ID is generated in the SQL instead of using a sequence, which ends up with a duplicate? In this example, I already had a single domain with ID=1, added a second (foo.example.com) within an org/loc context and the same ID was assigned.

  SQL (2.2ms)  INSERT INTO "domains" ("created_at", "dns_id", "fullname", "hostgroups_count", "hosts_count", "id", "name", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id"  [["created_at", Thu, 20 Mar 2014 08:24:47 UTC +00:00], ["dns_id", nil], ["fullname", ""], ["hostgroups_count", 0], ["hosts_count", 0], ["id", 1], ["name", "foo.example.com"], ["updated_at", Thu, 20 Mar 2014 08:24:47 UTC +00:00]]
PGError: ERROR:  duplicate key value violates unique constraint "domains_pkey" 
: INSERT INTO "domains" ("created_at", "dns_id", "fullname", "hostgroups_count", "hosts_count", "id", "name", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id" 
   (0.1ms)  ROLLBACK
Operation FAILED: ERROR:  duplicate key value violates unique constraint "domains_pkey" 

/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1171:in `get_last_result'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1171:in `exec_cache'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:665:in `block in exec_query'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:663:in `exec_query'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/database_statements.rb:63:in `exec_insert'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/database_statements.rb:90:in `insert'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/relation.rb:66:in `insert'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/persistence.rb:366:in `create'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/timestamp.rb:57:in `create'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/callbacks.rb:268:in `block in create'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:403:in `_run__3837851857623516097__create__137576595651868549__callbacks'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in `__run_callback'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in `_run_create_callbacks'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:in `run_callbacks'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/callbacks.rb:268:in `create'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/persistence.rb:347:in `create_or_update'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/callbacks.rb:264:in `block in create_or_update'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:425:in `_run__3837851857623516097__save__137576595651868549__callbacks'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in `__run_callback'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:in `run_callbacks'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/callbacks.rb:264:in `create_or_update'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/persistence.rb:84:in `save'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/validations.rb:50:in `save'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/attribute_methods/dirty.rb:22:in `save'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/transactions.rb:241:in `block (2 levels) in save'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/transactions.rb:208:in `transaction'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/transactions.rb:241:in `block in save'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/transactions.rb:252:in `rollback_active_record_state!'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/transactions.rb:240:in `save'
/usr/share/foreman/app/controllers/domains_controller.rb:16:in `create'

#5 Updated by Mike McCune over 3 years ago

is there a workaround for this? It is pretty fatal for getting much of anything done with upstream and downstream builds.

#6 Updated by Mike McCune over 3 years ago

looks like if you have Any Org selected it works fine. duh

#7 Updated by Mike McCune over 3 years ago

#8 Updated by Dominic Cleal over 3 years ago

  • Related to Bug #4932: Creating Compute Resource results in DB error added

#9 Updated by Joseph Magen over 3 years ago

  • Status changed from New to Assigned
  • Assigned To set to Joseph Magen

#10 Updated by Joseph Magen over 3 years ago

  • Status changed from Assigned to Ready For Testing

#11 Updated by Ohad Levy over 3 years ago

how was the initial database created? was it using plain install, or rather prod2dev rake task?

#12 Updated by Ohad Levy over 3 years ago

or rather this is a db restore?

#13 Updated by Justin Sherrill over 3 years ago

The db is created using the normal installer(s). I am able to reproduce on the nightly foreman installation with orgs and locations enabled. The rake task solution is not appropriate as the assumed cause is not true.

#14 Updated by Justin Sherrill over 3 years ago

Note that the error only occurs upon creation of the 2nd domain and an org needs to be selected during the creation of both.

#15 Updated by Justin Sherrill over 3 years ago

Also, only seems to occur with Rails 3.2.8 even in development (3.2.8 is currently used in production)

#16 Updated by Dominic Cleal over 3 years ago

  • Status changed from Ready For Testing to Assigned

Maybe this should be filed against RHSCL if the Rails fix can be identified.

#17 Updated by Ohad Levy over 3 years ago

  • Target version set to Sprint 22
  • Release set to 9

#18 Updated by Dominic Cleal over 3 years ago

  • Status changed from Assigned to Ready For Testing

#19 Updated by Dominic Cleal over 3 years ago

  • Bugzilla link set to https://bugzilla.redhat.com/show_bug.cgi?id=1079999

#20 Updated by Dominic Cleal over 3 years ago

  • Duplicated by Bug #4729: Importing subnet fails on unknown attribute added

#21 Updated by Joseph Magen over 3 years ago

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

#22 Updated by Dominic Cleal over 3 years ago

  • Release changed from 9 to 1.5.0

#23 Updated by Marek Hulán about 1 year ago

  • Related to Bug #16389: Can't create taxable e.g. domain object if I'm in context of specific organization or location added

Also available in: Atom PDF