{"action":"created","issue":{"url":"https://api.github.com/repos/airblade/paper_trail/issues/451","labels_url":"https://api.github.com/repos/airblade/paper_trail/issues/451/labels{/name}","comments_url":"https://api.github.com/repos/airblade/paper_trail/issues/451/comments","events_url":"https://api.github.com/repos/airblade/paper_trail/issues/451/events","html_url":"https://github.com/airblade/paper_trail/issues/451","id":52935424,"number":451,"title":"Unique database errors ","user":{"login":"pcragone","id":1450380,"avatar_url":"https://avatars.githubusercontent.com/u/1450380?v=3","gravatar_id":"","url":"https://api.github.com/users/pcragone","html_url":"https://github.com/pcragone","followers_url":"https://api.github.com/users/pcragone/followers","following_url":"https://api.github.com/users/pcragone/following{/other_user}","gists_url":"https://api.github.com/users/pcragone/gists{/gist_id}","starred_url":"https://api.github.com/users/pcragone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcragone/subscriptions","organizations_url":"https://api.github.com/users/pcragone/orgs","repos_url":"https://api.github.com/users/pcragone/repos","events_url":"https://api.github.com/users/pcragone/events{/privacy}","received_events_url":"https://api.github.com/users/pcragone/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2014-12-26T19:00:39Z","updated_at":"2015-02-13T03:45:48Z","closed_at":"2015-01-29T15:21:33Z","body":"Hi there -\r\n\r\nI'm having intermittent problems that I'm having trouble replicating, but I figured I'd reach out to you guys and see if you're familiar with it.\r\n\r\nLong story short, this is the error:\r\n```\r\nActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint \"versions_pkey\"\r\n```\r\n\r\nThe conditions:\r\n- in development\r\n- in console; I haven't noticed it happening when actually interacting with my application via a browser, but I don't religiously look at every request in the development log\r\n- Rails 4.1\r\n- confounding factor: using multitenancy as implemented by the Apartment gem, which utilizes postgres schemas. I have excluded the \"versions\" table, though, so this shouldn't be an issue\r\n\r\nIt's a big problem because this error ends up rolling back my update:\r\n```\r\n2.1.5 :006 > u.save(validate: false)\r\n   (0.4ms)  BEGIN\r\n  SQL (1.0ms)  UPDATE \"public\".\"users\" SET \"apartment_roles_mask\" = $1, \"updated_at\" = $2 WHERE \"public\".\"users\".\"id\" = 5  [[\"apartment_roles_mask\", \"\\\"hvremo\\\"=>\\\"5\\\",\\\"public\\\"=>\\\"32\\\"\"], [\"updated_at\r\n\", \"2014-12-26 18:54:43.412041\"]]\r\n  SQL (33.6ms)  INSERT INTO \"versions\" (\"created_at\", \"event\", \"item_id\", \"item_type\", \"object\") VALUES ($1, $2, $3, $4, $5) RETURNING \"id\"  [[\"created_at\", \"2014-12-26 18:54:43.467064\"], [\"event\", \"upd\r\nate\"], [\"item_id\", 5], [\"item_type\", \"User\"], [\"object\", \"---\\nid: 5\\nfirst_name: Peter\\nlast_name: Ragone\\nemail: peter@prmtech.com\\nusername: '350310'\\nold_data: \\ncreated_at: 2014-12-26 02:31:32.3762\r\n95000 Z\\nupdated_at: 2014-12-26 18:29:09.237037000 Z\\nencrypted_password: \\\"$2a$10$BsdfJlY51q3YRmuKe4MpoONq9hIgS2Lrrh8EQYpG.3IYRpzPtPNtq\\\"\\nreset_password_token: \\nreset_password_sent_at: \\nremember_cre\r\nated_at: \\nsign_in_count: 3\\ncurrent_sign_in_at: 2014-12-26 18:29:09.233149000 Z\\nlast_sign_in_at: 2014-12-26 03:50:52.172595000 Z\\ncurrent_sign_in_ip: !ruby/object:IPAddr\\n  family: 2\\n  addr: 21307064\r\n33\\n  mask_addr: 4294967295\\nlast_sign_in_ip: !ruby/object:IPAddr\\n  family: 2\\n  addr: 2130706433\\n  mask_addr: 4294967295\\nconfirmation_token: \\nconfirmed_at: 2014-12-26 02:40:15.863417000 Z\\nconfirma\r\ntion_sent_at: 2014-12-26 02:39:54.487143000 Z\\nunconfirmed_email: \\nfailed_attempts: 0\\nunlock_token: \\nlocked_at: \\napartment_roles_mask:\\n  hvremo: '5'\\n  public: '0'\\nflags:\\n  new_remo_als_user: 'fa\r\nlse'\\n  after_signup_complete: 'true'\\n  next_after_signup_step: 'false'\\n  email_confirmation_instructions_sent: 'true'\\ndefault_region_id: \\n\"]]\r\nPG::UniqueViolation: ERROR:  duplicate key value violates unique constraint \"versions_pkey\"\r\nDETAIL:  Key (id)=(1) already exists.\r\n: INSERT INTO \"versions\" (\"created_at\", \"event\", \"item_id\", \"item_type\", \"object\") VALUES ($1, $2, $3, $4, $5) RETURNING \"id\"\r\n   (0.5ms)  ROLLBACK\r\nActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint \"versions_pkey\"\r\nDETAIL:  Key (id)=(1) already exists.\r\n: INSERT INTO \"versions\" (\"created_at\", \"event\", \"item_id\", \"item_type\", \"object\") VALUES ($1, $2, $3, $4, $5) RETURNING \"id\"\r\n        from /Users/pragone/.rvm/gems/ruby-2.1.5@remoonline/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:834:in `get_last_result'\r\n        from /Users/pragone/.rvm/gems/ruby-2.1.5@remoonline/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:834:in `block in exec_cache'\r\n        from /Users/pragone/.rvm/gems/ruby-2.1.5@remoonline/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'\r\n        from /Users/pragone/.rvm/gems/ruby-2.1.5@remoonline/gems/activesupport-4.1.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'\r\n```\r\n\r\nI re-issue the save command, and everything works fine.\r\n\r\nAre you familiar with this condition happening?  Can you give me any more insight?  I'm happy to try and replicate this more and identify it, but, like I said, it seems to be an intermittent problem.\r\n\r\nEdit: Looking at this some more, it seems to be issuing a double-insert into versions; I'm not sure why, when there's clearly only a single update to the users table."},"comment":{"url":"https://api.github.com/repos/airblade/paper_trail/issues/comments/74200927","html_url":"https://github.com/airblade/paper_trail/issues/451#issuecomment-74200927","issue_url":"https://api.github.com/repos/airblade/paper_trail/issues/451","id":74200927,"user":{"login":"tombroomfield","id":5423793,"avatar_url":"https://avatars.githubusercontent.com/u/5423793?v=3","gravatar_id":"","url":"https://api.github.com/users/tombroomfield","html_url":"https://github.com/tombroomfield","followers_url":"https://api.github.com/users/tombroomfield/followers","following_url":"https://api.github.com/users/tombroomfield/following{/other_user}","gists_url":"https://api.github.com/users/tombroomfield/gists{/gist_id}","starred_url":"https://api.github.com/users/tombroomfield/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tombroomfield/subscriptions","organizations_url":"https://api.github.com/users/tombroomfield/orgs","repos_url":"https://api.github.com/users/tombroomfield/repos","events_url":"https://api.github.com/users/tombroomfield/events{/privacy}","received_events_url":"https://api.github.com/users/tombroomfield/received_events","type":"User","site_admin":false},"created_at":"2015-02-13T03:45:48Z","updated_at":"2015-02-13T03:45:48Z","body":"Hi,\r\nI am also getting this error when I save a previous version in order to rollback.\r\n\r\nThanks,\r\nTom."}}