This project is archived and is in readonly mode.

#6107 ✓stale
coffeeaddict_nl

update_counters_with_lock does not call observers

Reported by coffeeaddict_nl | December 3rd, 2010 @ 08:21 AM

update_counters_with_lock from ActiveRecord::Locking::Optimistic::ClassMethods does not trigger the observer callbacks on the model.

I am not really sure whether this is a bug... But from my point of view this is not the expected behaviour.

Feel free to elaborate as to why this is expected behaviour and promptly close this ticket. If this is considered a bug I would be happy to render and provide a patch.

I've (manually) tested this to be true in both Rails 2.3.8 and 3.0.3

Comments and changes to this ticket

  • Neeraj Singh

    Neeraj Singh December 4th, 2010 @ 04:13 AM

    • Importance changed from “” to “Low”

    I think it is a bug. Please feel free to attach a patch for 3.0.3. Patches for 2.3 branch is a littler harder to get accepted since that is a maintenance branch.

  • coffeeaddict_nl

    coffeeaddict_nl December 6th, 2010 @ 06:08 PM

    After some further investigation as to where to place this patch, it turns out that update_counters in ActiveRecord::Locking::Optimistic::ClassMethods overrides the version from ActiveRecord::CounterCache and just inserts the lock_column as one of the counters.

    This brings to light the question whether it is valid to call the observers on counters...

    Imho it is. I use counters for stock and it would seem only natural that a change in stock would trigger orders to be placed in backorder (or released from it) but there could be counter arguments; The behaviour is no longer expected as it hasn't occurred before and people rely on the fact the update_counters does not call observers.

  • Neeraj Singh

    Neeraj Singh December 9th, 2010 @ 02:30 AM

    Can you attach a failing test. I think it is a bug. It is not documented and updating counter should fire callback. Client can do whatever it wants to do.

    No need to provide patch for 2.3.x branch . Just work on rails edge.

  • rails

    rails March 14th, 2011 @ 12:00 AM

    • Tag changed from activerecord::locking::optimistic::classmethods, callback, observer, update_counters_with_locks to activerecordlockingoptimisticclassmethods, callback, observer, update_counters_with_locks
    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • rails

    rails March 14th, 2011 @ 12:00 AM

    • State changed from “open” to “stale”
  • klkk

Create your profile

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

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages