#25 new
nbarthelemy

[PATCH] Edge callback overrides inconsistently pass arguments

Reported by nbarthelemy | April 4th, 2008 @ 02:20 PM

According to the documentation in attachment_fu.rb callbacks are suppose to get the ActiveRecord object as their first argument. Using the new callback implementation in Rails, only a single argument is passed. I believe this is because in the 2.0 override, the callback is called with both the AR object and the argument.

          # line 445 attachment_fu.rb
          # Rails 2.0
          def callback_with_args(method, arg = self)
            notify(method)

            result = nil
            callbacks_for(method).each do |callback|
              result = callback.call(self, arg)
              return false if result == false
            end
            result
          end

In the 2.1+ overrides, the calling of the callback is left up to ActiveSupport::Callbacks::CallbackChain.run, where the callback is called with out the argument because the argument is conditionally replaces the AR object.

Callbacks work as documented using Rails 2.0.

Comments and changes to this ticket

  • Matt Jones

    Matt Jones June 11th, 2008 @ 06:25 AM

    Has anything been done about this? The first comment/change to the ticket says that it has been marked as spam, yet zeno and I are both having this issue with the released version of rails 2.1.

    In my application, I use mini_magick and I need to convert images to

    black and white and sepia tones. In Rails 1,2,3, this used to work:

    after_resize do |record,img|

    logger.debug "img = #{img}"

    logger.debug "record = #{record}"

    logger.debug "self = #{self}"

    logger.debug "record.thumbnail = #{record.thumbnail}"

    end

    Now that I'm trying to use Rails 2.1, the log file says:

    img =

    record = #

    self = Photo

    And it throws an exception on record.thumbnail.

  • Mike Champion

    Mike Champion June 24th, 2008 @ 03:57 PM

    I see the same thing. Inside after_resize the parameter is for the image itself and doing "self.class" returns Class and inspecting it looks like it includes many Rails modules, but not AR::Base.

  • ---

    --- August 1st, 2008 @ 08:28 AM

    • Tag set to after_resize, attachment_fu, bug, callback

    same behaviour, it's driving me crazy.

    --

    ruby 1.8.6 (2008-03-03 patchlevel 114)

    rails 2.1.0

    attachment_fu (06/25/08 master tree)

  • James Kebinger

    James Kebinger September 16th, 2008 @ 10:50 PM

    • Tag changed from after_resize, attachment_fu, bug, callback to after_resize, attachment_fu, bug, callback

    I just ran into this with rails 2.1 while running the test suite for attachment_fu, getting errors on after_resize callback where the first argument was actually the image, instead of the object.

    The attached patch provides a fix. Hopefully I generated it correctly as I'm new to git

  • James Kebinger

    James Kebinger September 16th, 2008 @ 10:58 PM

    • Title changed from “Edge callback overrides inconsistently pass arguments” to “[PATCH] Edge callback overrides inconsistently pass arguments”
    • Tag changed from after_resize, attachment_fu, bug, callback to after_resize, attachment_fu, bug, callback, patch

    should have changed the title?

  • James Kebinger

    James Kebinger September 18th, 2008 @ 02:31 PM

    Earlier patch didn't actually work for the single argument callbacks. This patch supersedes my earlier patch. A shame to have to modify all the processors to fix this.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Pages