Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Do not evaluate :if arguments when :on is not satisfied for transaction callbacks #28063
This addresses #28019 by prepending the
class Topic < ActiveRecord::Base after_commit :do_something, on: [:create, :update], if: :check_something? end topic = Topic.create #=> Calls :check_something? topic.save #=> Calls :check_something? topic.destroy #=> No longer calls :check_something?
changed the title from
Do not evaluate given `:if` arguments when the `:on` action check is not satisfied for transaction callbacks
Do not evaluate `:if` arguments when the `:on` action check is not satisfied for transaction callbacks
Feb 19, 2017
@rafaelfranca surely people shouldn't be putting any model-changing logic in the :if statements? It should only be used to evaluate a boolean expression, so as I understand it nothing would change for those who might expect the 'if' before the 'on'. But for those who expect the 'on' before the 'if', unnecessarily evaluating the 'if' statement could raise an error. (In my case, the 'if' was being unnecessarily evaluated on destroy, when it was specified for an 'on: :update', and during the destroy lifecycle an association that would otherwise be present was not.)
Yeah, I think this should be relatively safe: the
IOW, it is a behavioural change, but not one that seems likely to affect applications using the API in good faith.