You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#45280 broke the expected and documented behaviour by introducing a breaking change in Rails 7.1.
It leads to hard-to-find silent bugs and should be reverted, there's no workaround except disabling it completely with config.active_record.run_commit_callbacks_on_first_saved_instances_in_transaction = true.
The problem it was trying to solve is well-documented and easily dealt with reload.
Steps to reproduce
Oversimplified example:
# frozen_string_literal: truerequire"bundler/inline"gemfile(true)dosource"https://rubygems.org"git_source(:github){ |repo| "https://github.com/#{repo}.git"}gem"rails"# If you want to test against edge Rails replace the previous line with this:# gem "rails", github: "rails/rails", branch: "main"gem"sqlite3"endrequire"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.definedocreate_table:posts,force: truedo |t|
t.integer:comments_count,null: false,default: 0endcreate_table:comments,force: truedo |t|
t.boolean:hidden,null: false,default: falset.integer:post_idendendclassPost < ActiveRecord::Basehas_many:commentsdefupdate_comments_count!self.update!(comments_count: comments.size)endendclassComment < ActiveRecord::Basebelongs_to:postafter_commit:update_postsdefupdate_postsifsaved_change_to_post_id?post.update_comments_count!endendendclassBugTest < Minitest::Testdeftest_association_stuffpost_1=Post.create!post_1.comments.create!assert_equal1,post_1.comments_countpost_2=Post.create!comment=post_2.comments.buildPost.transactiondocomment.save!comment.update!(hidden: true)endassert_equal1,post_1.comments_countassert_equal1,post_2.comments_countendend
Expected behavior
saved_change_to_post_id? == true
Actual behavior
saved_change_to_post_id? == false
System configuration
Rails version: 7.1+ Ruby version: 3.2.3
The text was updated successfully, but these errors were encountered:
@jreed-mt no, it's not. The current issue is reproduced on a much simpler configuration with only one model. You only need Rails 7.1 with default configuration + after_commit => changes is empty even there were changes
#45280 broke the expected and documented behaviour by introducing a breaking change in Rails 7.1.
It leads to hard-to-find silent bugs and should be reverted, there's no workaround except disabling it completely with
config.active_record.run_commit_callbacks_on_first_saved_instances_in_transaction = true
.The problem it was trying to solve is well-documented and easily dealt with
reload
.Steps to reproduce
Oversimplified example:
Expected behavior
saved_change_to_post_id? == true
Actual behavior
saved_change_to_post_id? == false
System configuration
Rails version: 7.1+
Ruby version: 3.2.3
The text was updated successfully, but these errors were encountered: