Skip to content

Wrap discard methods in a transaction#124

Merged
jarednorman merged 1 commit into
jhawthorn:masterfrom
jarednorman:pr-84
May 27, 2026
Merged

Wrap discard methods in a transaction#124
jarednorman merged 1 commit into
jhawthorn:masterfrom
jarednorman:pr-84

Conversation

@jarednorman

Copy link
Copy Markdown
Collaborator

We didn't have enough PRs with the same name, so this is my cherry pick of #84. (@grncdr I actually did this mostly last night before you'd pushed up yours, but thank you for doing that! My bad for not saying I would do it.)

This varies from the original mainly in that it removes the error handling which should be unnecessary in modern versions of ActiveRecord.

This seeks to solve issue: jhawthorn#77

Given the situation where a `before/after` callback fails, particularly
with related records, we shouldn't still discard records.

Note: This is leveraging a private API that exists in
ActiveRecord::Transactions:

https://github.com/rails/rails/blob/cd2949d2d936daa89b7e23f816f1c004aee85461/activerecord/lib/active_record/transactions.rb#L345

Co-authored-by: Will Cosgrove <will@cosgrove.email>
@jarednorman jarednorman merged commit 7a0a61c into jhawthorn:master May 27, 2026
8 checks passed
@jarednorman jarednorman deleted the pr-84 branch May 27, 2026 20:43
@grncdr

grncdr commented May 27, 2026

Copy link
Copy Markdown

No worries, glad to see it going in!

(p.s. Hello 👋 things are good! Hope you're also doing well 😄)

@jarednorman

Copy link
Copy Markdown
Collaborator Author

@grncdr I just cut a 2.0.0 release! (Also I was looking through an ancient Flickr account of mine today and found this.)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants