{"action":"closed","number":9448,"pull_request":{"url":"https://api.github.com/repos/rails/rails/pulls/9448","id":4333559,"html_url":"https://github.com/rails/rails/pull/9448","diff_url":"https://github.com/rails/rails/pull/9448.diff","patch_url":"https://github.com/rails/rails/pull/9448.patch","issue_url":"https://api.github.com/repos/rails/rails/issues/9448","number":9448,"state":"closed","locked":false,"title":"Optimistic locking destroy bug","user":{"login":"bdmac","id":47326,"avatar_url":"https://avatars.githubusercontent.com/u/47326?v=3","gravatar_id":"","url":"https://api.github.com/users/bdmac","html_url":"https://github.com/bdmac","followers_url":"https://api.github.com/users/bdmac/followers","following_url":"https://api.github.com/users/bdmac/following{/other_user}","gists_url":"https://api.github.com/users/bdmac/gists{/gist_id}","starred_url":"https://api.github.com/users/bdmac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bdmac/subscriptions","organizations_url":"https://api.github.com/users/bdmac/orgs","repos_url":"https://api.github.com/users/bdmac/repos","events_url":"https://api.github.com/users/bdmac/events{/privacy}","received_events_url":"https://api.github.com/users/bdmac/received_events","type":"User","site_admin":false},"body":"This PR is only meant as a discussion point at this time.  I do not\r\ncurrently have a fix here.\r\n\r\nThere seems to be a problem when using optimistic locking with\r\n:dependent => :destroy and :touch => true.  This pull request\r\nattempts to expose the error although I do not yet have a\r\nfix.  Please see the new test in locking_test and note that\r\nit fails.  This failure means that when attempting to destroy\r\na model object with :dependent => :destroy on a realtionship\r\nwhere the inverse has :touch => true results in:\r\n\r\nActiveRecord::StaleObjectError: Attempted to destroy a stale object\r\n\r\nIf in the new test we attempted to do `p.destroy` we would trigger the\r\nStaleObjectError.  This is because the lock_version of the Person in\r\nthe database gets updated when the :reference is destroyed due to\r\n:touch => true but the in-memory lock_version on the person object,\r\np, is NOT updated so when the destroy is attempted it thinks it is\r\nstale.\r\n\r\nAny advice on how to fix this in AR without breaking anything else\r\nwould be appreciated.","created_at":"2013-02-26T19:35:33Z","updated_at":"2015-01-02T23:33:53Z","closed_at":"2015-01-02T23:33:53Z","merged_at":null,"merge_commit_sha":"4118f23359f40eb10ca9442669ba8228e54a476b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rails/rails/pulls/9448/commits","review_comments_url":"https://api.github.com/repos/rails/rails/pulls/9448/comments","review_comment_url":"https://api.github.com/repos/rails/rails/pulls/comments/{number}","comments_url":"https://api.github.com/repos/rails/rails/issues/9448/comments","statuses_url":"https://api.github.com/repos/rails/rails/statuses/3d7c6b439ee44a82473b1575027fa2a89882724f","head":{"label":"bdmac:optimistic-locking-dependent-destroy","ref":"optimistic-locking-dependent-destroy","sha":"3d7c6b439ee44a82473b1575027fa2a89882724f","user":{"login":"bdmac","id":47326,"avatar_url":"https://avatars.githubusercontent.com/u/47326?v=3","gravatar_id":"","url":"https://api.github.com/users/bdmac","html_url":"https://github.com/bdmac","followers_url":"https://api.github.com/users/bdmac/followers","following_url":"https://api.github.com/users/bdmac/following{/other_user}","gists_url":"https://api.github.com/users/bdmac/gists{/gist_id}","starred_url":"https://api.github.com/users/bdmac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bdmac/subscriptions","organizations_url":"https://api.github.com/users/bdmac/orgs","repos_url":"https://api.github.com/users/bdmac/repos","events_url":"https://api.github.com/users/bdmac/events{/privacy}","received_events_url":"https://api.github.com/users/bdmac/received_events","type":"User","site_admin":false},"repo":{"id":4983096,"name":"rails","full_name":"bdmac/rails","owner":{"login":"bdmac","id":47326,"avatar_url":"https://avatars.githubusercontent.com/u/47326?v=3","gravatar_id":"","url":"https://api.github.com/users/bdmac","html_url":"https://github.com/bdmac","followers_url":"https://api.github.com/users/bdmac/followers","following_url":"https://api.github.com/users/bdmac/following{/other_user}","gists_url":"https://api.github.com/users/bdmac/gists{/gist_id}","starred_url":"https://api.github.com/users/bdmac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bdmac/subscriptions","organizations_url":"https://api.github.com/users/bdmac/orgs","repos_url":"https://api.github.com/users/bdmac/repos","events_url":"https://api.github.com/users/bdmac/events{/privacy}","received_events_url":"https://api.github.com/users/bdmac/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bdmac/rails","description":"Ruby on Rails","fork":true,"url":"https://api.github.com/repos/bdmac/rails","forks_url":"https://api.github.com/repos/bdmac/rails/forks","keys_url":"https://api.github.com/repos/bdmac/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bdmac/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bdmac/rails/teams","hooks_url":"https://api.github.com/repos/bdmac/rails/hooks","issue_events_url":"https://api.github.com/repos/bdmac/rails/issues/events{/number}","events_url":"https://api.github.com/repos/bdmac/rails/events","assignees_url":"https://api.github.com/repos/bdmac/rails/assignees{/user}","branches_url":"https://api.github.com/repos/bdmac/rails/branches{/branch}","tags_url":"https://api.github.com/repos/bdmac/rails/tags","blobs_url":"https://api.github.com/repos/bdmac/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bdmac/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bdmac/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/bdmac/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bdmac/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/bdmac/rails/languages","stargazers_url":"https://api.github.com/repos/bdmac/rails/stargazers","contributors_url":"https://api.github.com/repos/bdmac/rails/contributors","subscribers_url":"https://api.github.com/repos/bdmac/rails/subscribers","subscription_url":"https://api.github.com/repos/bdmac/rails/subscription","commits_url":"https://api.github.com/repos/bdmac/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/bdmac/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/bdmac/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/bdmac/rails/issues/comments/{number}","contents_url":"https://api.github.com/repos/bdmac/rails/contents/{+path}","compare_url":"https://api.github.com/repos/bdmac/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bdmac/rails/merges","archive_url":"https://api.github.com/repos/bdmac/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bdmac/rails/downloads","issues_url":"https://api.github.com/repos/bdmac/rails/issues{/number}","pulls_url":"https://api.github.com/repos/bdmac/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/bdmac/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/bdmac/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bdmac/rails/labels{/name}","releases_url":"https://api.github.com/repos/bdmac/rails/releases{/id}","created_at":"2012-07-11T01:41:58Z","updated_at":"2014-05-10T20:18:56Z","pushed_at":"2013-03-27T21:11:45Z","git_url":"git://github.com/bdmac/rails.git","ssh_url":"git@github.com:bdmac/rails.git","clone_url":"https://github.com/bdmac/rails.git","svn_url":"https://github.com/bdmac/rails","homepage":"http://rubyonrails.org","size":89850,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"rails:master","ref":"master","sha":"5112a6ccdfb930200d6d476f5e40bfe3d1a6ef33","user":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?v=3","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"repo":{"id":8514,"name":"rails","full_name":"rails/rails","owner":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?v=3","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rails/rails","description":"Ruby on Rails","fork":false,"url":"https://api.github.com/repos/rails/rails","forks_url":"https://api.github.com/repos/rails/rails/forks","keys_url":"https://api.github.com/repos/rails/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rails/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rails/rails/teams","hooks_url":"https://api.github.com/repos/rails/rails/hooks","issue_events_url":"https://api.github.com/repos/rails/rails/issues/events{/number}","events_url":"https://api.github.com/repos/rails/rails/events","assignees_url":"https://api.github.com/repos/rails/rails/assignees{/user}","branches_url":"https://api.github.com/repos/rails/rails/branches{/branch}","tags_url":"https://api.github.com/repos/rails/rails/tags","blobs_url":"https://api.github.com/repos/rails/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rails/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rails/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/rails/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rails/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/rails/rails/languages","stargazers_url":"https://api.github.com/repos/rails/rails/stargazers","contributors_url":"https://api.github.com/repos/rails/rails/contributors","subscribers_url":"https://api.github.com/repos/rails/rails/subscribers","subscription_url":"https://api.github.com/repos/rails/rails/subscription","commits_url":"https://api.github.com/repos/rails/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/rails/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/rails/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/rails/rails/issues/comments/{number}","contents_url":"https://api.github.com/repos/rails/rails/contents/{+path}","compare_url":"https://api.github.com/repos/rails/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rails/rails/merges","archive_url":"https://api.github.com/repos/rails/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rails/rails/downloads","issues_url":"https://api.github.com/repos/rails/rails/issues{/number}","pulls_url":"https://api.github.com/repos/rails/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/rails/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/rails/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rails/rails/labels{/name}","releases_url":"https://api.github.com/repos/rails/rails/releases{/id}","created_at":"2008-04-11T02:19:47Z","updated_at":"2015-01-02T22:57:27Z","pushed_at":"2015-01-02T22:57:27Z","git_url":"git://github.com/rails/rails.git","ssh_url":"git@github.com:rails/rails.git","clone_url":"https://github.com/rails/rails.git","svn_url":"https://github.com/rails/rails","homepage":"http://rubyonrails.org","size":369616,"stargazers_count":24468,"watchers_count":24468,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9430,"mirror_url":null,"open_issues_count":724,"forks":9430,"open_issues":724,"watchers":24468,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/9448"},"html":{"href":"https://github.com/rails/rails/pull/9448"},"issue":{"href":"https://api.github.com/repos/rails/rails/issues/9448"},"comments":{"href":"https://api.github.com/repos/rails/rails/issues/9448/comments"},"review_comments":{"href":"https://api.github.com/repos/rails/rails/pulls/9448/comments"},"review_comment":{"href":"https://api.github.com/repos/rails/rails/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/rails/rails/pulls/9448/commits"},"statuses":{"href":"https://api.github.com/repos/rails/rails/statuses/3d7c6b439ee44a82473b1575027fa2a89882724f"}},"merged":false,"mergeable":true,"mergeable_state":"clean","merged_by":null,"comments":6,"review_comments":1,"commits":1,"additions":10,"deletions":1,"changed_files":2}}