Skip to content

Instantly share code, notes, and snippets.

@Tonkpils
Last active April 16, 2021 14:10
Show Gist options
  • Save Tonkpils/06524f6e48e383ed1ef70502b0c00d15 to your computer and use it in GitHub Desktop.
Save Tonkpils/06524f6e48e383ed1ef70502b0c00d15 to your computer and use it in GitHub Desktop.
SystemStackError reproduction script
# frozen_string_literal: true
## SystemStackError introduced by https://github.com/rails/rails/pull/41860
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Good
# gem "rails", github: "rails/rails", ref: "2bbb519"
# Bad
gem "rails", github: "rails/rails", ref: "ae56ecd"
gem "sqlite3"
end
require "active_record"
require "minitest/autorun"
require "logger"
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :comments, force: true do |t|
t.string :body
t.integer :public
end
end
class Comment < ActiveRecord::Base
after_update :update_again, if: :saved_change_to_public?
def update_again
update_attribute :body, nil
end
end
class BugTest < Minitest::Test
def test_association_stuff
comment = Comment.create(public: false, body: nil)
comment.update(public: true)
assert_equal 1, Comment.count
assert Comment.first.public?
assert_nil Comment.first.body
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment