GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
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 topic.replies.build.save, 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.
Failing testcase demonstrating has_many#create not supporting rollback
@jdelStrother are you still seeing this behavior?
Yeah, still seems to fail in 4-2-stable (23e6743) and master (2c79122)