Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:if option in after_commit on: :create processed during destroy #28019

Closed
niborg opened this issue Feb 15, 2017 · 2 comments
Closed

:if option in after_commit on: :create processed during destroy #28019

niborg opened this issue Feb 15, 2017 · 2 comments

Comments

@niborg
Copy link

niborg commented Feb 15, 2017

In short, an after_commit :if option is still triggered after the destroy lifecycle even if the after_commit is limited to, say, [:create, :update]. This doesn't seem like it should be expected behavior.

Steps to reproduce

Here is a gist.

Expected behavior

Since the after_commit is limited to being triggered on the create and update events, and therefore never be triggered on destroy events, it seems counter-intuitive for ActiveRecord to bother processing the :if option, and can cause errors if the code within the :if option assumes that it will only be run when the model is valid and existing.

Actual behavior

The after_commit :if option is triggered on destroy.

System configuration

Rails version: Gist reproduces this in 5.0.1. I discovered this issue in 4.2.7.

Ruby version: 2.3.1

@st0012
Copy link
Contributor

st0012 commented Feb 16, 2017

Not related to the subject but I think you can change the gist's filename extension to .rb to make it more readable.

@Erol
Copy link
Contributor

Erol commented Feb 18, 2017

If you're not yet working on it, I think I can come up with a PR to address this.

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

No branches or pull requests

5 participants