RecordInvalid rollback is ignored when creating via has_many #13665

wants to merge 1 commit into


None yet
4 participants

jdelStrother commented Jan 10, 2014

I have an after_save hook that raises RecordInvalid if the record's associations aren't compatible. If the record is created via a has_many association, then the RecordInvalid exception is swallowed somewhere and doesn't cause the save to fail.

I was struggling to figure out a fix, but here's a failing test case demonstrating the problem.

Interestingly, if you replace topic.replies.create with, then the rollback works as expected.

The same problem also occurs via has_many :through - eg with Post->Tagging->Tag, post.tags.create would succeed even if Tag raises RecordInvalid in its after_save hook.


magikid commented Jul 16, 2015

@jdelStrother are you still seeing this behavior?


jdelStrother commented Jul 17, 2015

Yeah, still seems to fail in 4-2-stable (23e6743) and master (2c79122)

rafaelfranca self-assigned this Aug 31, 2015

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