calling save in after_commit(:on => :create) block triggers same block again #6207

gnufied opened this Issue May 8, 2012 · 3 comments


None yet

3 participants

gnufied commented May 8, 2012

Following code:

class User < ActiveRecord::Base
  attr_accessible :name
  after_commit :cache_user, :on => :create

  def cache_user
    puts "Caching user"
    self.cached = true

triggers same cache_user method again when save gets called from cache_user method. I believe, calling save from after_commit(:on => :create) hook should ideally only trigger if there is a after_commit(:on => :update) callback is registered.
The reason this is happening is - recorded transaction states get cleared only after after_commit callback returns, whereas I believe this bug can be fixed by clearing transaction state before entering after_commit callback.

gnufied commented May 9, 2012

I have attached a pull request, #6226 . @tenderlove can you please have a look?


Closed by #6226

Does anyone know what version of rails the fix for this made it into?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment