Project

General

Profile

Actions

Bug #4731

closed

Creating domain when organization selected produces duplicate key error

Added by Ivan Necas over 10 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
High
Assignee:
Category:
Database
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

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 3 (0 open3 closed)

Related to Foreman - Bug #4932: Creating Compute Resource results in DB errorDuplicate03/28/2014Actions
Related to Foreman - Bug #16389: Can't create taxable e.g. domain object if I'm in context of specific organization or locationClosedMarek Hulán08/31/2016Actions
Has duplicate Foreman - Bug #4729: Importing subnet fails on unknown attributeDuplicate03/19/2014Actions
Actions #1

Updated by Ivan Necas over 10 years ago

  • Description updated (diff)
Actions #2

Updated by Ivan Necas over 10 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" 
Actions #3

Updated by Dominic Cleal over 10 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'
Actions #5

Updated by Mike McCune over 10 years ago

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

Actions #6

Updated by Mike McCune over 10 years ago

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

Actions #7

Updated by Mike McCune over 10 years ago

Actions #8

Updated by Dominic Cleal over 10 years ago

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

Updated by Joseph Magen over 10 years ago

  • Status changed from New to Assigned
  • Assignee set to Joseph Magen
Actions #10

Updated by Joseph Magen over 10 years ago

  • Status changed from Assigned to Ready For Testing
Actions #11

Updated by Ohad Levy over 10 years ago

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

Actions #12

Updated by Ohad Levy over 10 years ago

or rather this is a db restore?

Actions #13

Updated by Justin Sherrill over 10 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.

Actions #14

Updated by Justin Sherrill over 10 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.

Actions #15

Updated by Justin Sherrill over 10 years ago

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

Actions #16

Updated by Dominic Cleal over 10 years ago

  • Status changed from Ready For Testing to Assigned

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

Actions #17

Updated by Ohad Levy over 10 years ago

  • Target version set to 1.8.4
  • Translation missing: en.field_release set to 9
Actions #18

Updated by Dominic Cleal over 10 years ago

  • Status changed from Assigned to Ready For Testing
Actions #19

Updated by Dominic Cleal over 10 years ago

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

Updated by Dominic Cleal over 10 years ago

  • Has duplicate Bug #4729: Importing subnet fails on unknown attribute added
Actions #21

Updated by Joseph Magen over 10 years ago

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

Updated by Dominic Cleal over 10 years ago

  • Translation missing: en.field_release changed from 9 to 4
Actions #23

Updated by Marek Hulán about 8 years ago

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

Also available in: Atom PDF