{"action":"opened","issue":{"url":"https://api.github.com/repos/rails/rails/issues/22066","labels_url":"https://api.github.com/repos/rails/rails/issues/22066/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/22066/comments","events_url":"https://api.github.com/repos/rails/rails/issues/22066/events","html_url":"https://github.com/rails/rails/issues/22066","id":113255434,"number":22066,"title":"new_record? returns false after rollback if record is created and then updated in the transaction","user":{"login":"wildfiler","id":2605257,"avatar_url":"https://avatars.githubusercontent.com/u/2605257?v=3","gravatar_id":"","url":"https://api.github.com/users/wildfiler","html_url":"https://github.com/wildfiler","followers_url":"https://api.github.com/users/wildfiler/followers","following_url":"https://api.github.com/users/wildfiler/following{/other_user}","gists_url":"https://api.github.com/users/wildfiler/gists{/gist_id}","starred_url":"https://api.github.com/users/wildfiler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wildfiler/subscriptions","organizations_url":"https://api.github.com/users/wildfiler/orgs","repos_url":"https://api.github.com/users/wildfiler/repos","events_url":"https://api.github.com/users/wildfiler/events{/privacy}","received_events_url":"https://api.github.com/users/wildfiler/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-10-25T21:34:20Z","updated_at":"2015-10-25T21:34:20Z","closed_at":null,"body":"The following code fails in rails > 4.0 and in master. It works fine for 3.2.22.\r\n\r\nFor the second call `new_record?` returns correct value, but `id` is still present for this record.\r\n\r\n```ruby\r\nbegin\r\n  require 'bundler/inline'\r\nrescue LoadError => e\r\n  $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'\r\n  raise e\r\nend\r\n\r\ngemfile(true) do\r\n  source 'https://rubygems.org'\r\n  gem 'rails', github: 'rails/rails'\r\n  gem 'arel', github: 'rails/arel'\r\n  gem 'rack', github: 'rack/rack'\r\n  gem 'sprockets', github: 'rails/sprockets'\r\n  gem 'sprockets-rails', github: 'rails/sprockets-rails'\r\n  gem 'sass-rails', github: 'rails/sass-rails'\r\n  gem 'sqlite3'\r\nend\r\n\r\nrequire 'active_record'\r\nrequire 'minitest/autorun'\r\nrequire 'logger'\r\n\r\n# Ensure backward compatibility with Minitest 4\r\nMinitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)\r\n\r\n# This connection will do for database-independent bug reports.\r\nActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')\r\nActiveRecord::Base.logger = Logger.new(STDOUT)\r\n\r\nActiveRecord::Schema.define do\r\n  create_table :posts, force: true do |t|\r\n  end\r\nend\r\n\r\nclass Post < ActiveRecord::Base\r\nend\r\n\r\nclass BugTest < Minitest::Test\r\n  def test_rollback_restore_state_on_object_created_and_updated_in_transaction\r\n    Post.transaction do\r\n      @post = Post.create!\r\n      @post.touch\r\n      raise ActiveRecord::Rollback\r\n    end\r\n    \r\n    assert @post.new_record?\r\n  end\r\n\r\n  def test_new_record_state_dont_changes_for_sequential_calls\r\n    Post.transaction do\r\n      @post = Post.create!\r\n      @post.touch\r\n      raise ActiveRecord::Rollback\r\n    end\r\n    \r\n    assert_equal @post.new_record?, @post.new_record?\r\n  end\r\nend\r\n```"}}