mongodb/mongoid · error · ArgumentError
:on conditions for after_commit and after_rollback callbacks
Error message
:on conditions for after_commit and after_rollback callbacks have to be one of #{CALLBACK_ACTIONS} What it means
Error ":on conditions for after_commit and after_rollback callbacks have to be one of #{CALLBACK_ACTIONS}" thrown in mongodb/mongoid.
Source
Thrown at lib/mongoid/clients/sessions.rb:226
return unless options[:on]
fire_on = Array(options[:on])
assert_valid_transaction_action(fire_on)
options[:if] = [
-> { transaction_include_any_action?(fire_on) },
*options[:if]
]
end
# Asserts that the given actions are valid for after_commit
# and after_rollback callbacks.
#
# @param [ Array<Symbol> ] actions Actions to be checked.
# @raise [ ArgumentError ] If any of the actions is not valid.
def assert_valid_transaction_action(actions)
return unless (actions - CALLBACK_ACTIONS).any?
raise ArgumentError,
":on conditions for after_commit and after_rollback callbacks have to be one of #{CALLBACK_ACTIONS}"
end
def transaction_include_any_action?(actions)
actions.any? do |action|
case action
when :create
persisted? && previously_new_record?
when :update
!(previously_new_record? || destroyed?)
when :destroy
destroyed?
end
end
end
end
privateView on GitHub (pinned to 0da0e23d71)
When it happens
Trigger: Thrown at lib/mongoid/clients/sessions.rb:226 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of mongodb/mongoid@0da0e23d71 (2026-08-23).
Data as JSON: /api/errors/9a497d3ef06a0e10.
Report an issue: GitHub.