fix(refunds): persist log entries when processing refunds#6456
Open
RamblesShambles wants to merge 1 commit intosolidusio:mainfrom
Open
fix(refunds): persist log entries when processing refunds#6456RamblesShambles wants to merge 1 commit intosolidusio:mainfrom
RamblesShambles wants to merge 1 commit intosolidusio:mainfrom
Conversation
Refund#perform! used `log_entries.build` which only creates an in-memory association. While Rails may cascade the save for persisted parent records, using `create!` matches the pattern used by Payment#record_response and guarantees immediate persistence with proper error reporting. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
9934b9a to
65a4321
Compare
jarednorman
approved these changes
Apr 27, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6456 +/- ##
==========================================
- Coverage 89.66% 89.45% -0.22%
==========================================
Files 990 919 -71
Lines 20793 18981 -1812
==========================================
- Hits 18645 16980 -1665
+ Misses 2148 2001 -147 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When processing a refund via
Refund#perform!, the log entry recording the gateway response is built in memory but may not be persisted to the database. This means the admin payment page shows no log entry for the refund operation.Root cause:
log_entries.buildcreates an in-memory association that relies on Rails' save cascade behavior. The Payment model useslog_entries.create!for the same purpose, which guarantees immediate persistence.Fix: Change
log_entries.buildtolog_entries.create!inRefund#perform!, matching the established pattern inPayment#record_response.Closes #4866
How to reproduce
What changed
core/app/models/spree/refund.rb— Changedlog_entries.buildtolog_entries.create!core/spec/models/spree/refund_spec.rb— Added regression test verifying log entry persistence with correct source typeTrade-offs
create!persists the log entry immediately, before the refund itself is saved. If the refund save fails after the gateway credit succeeds, the log entry remains in the DB. This is the same behavior asPayment#record_responseand is acceptable because the gateway operation is already irreversible at that point.🤖 Generated with Claude Code