-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Issue with Transactional Rollbacks during Test Environments with Spree Log Entries #2277
Conversation
core/app/models/spree/log_entry.rb
Outdated
@@ -4,7 +4,7 @@ class LogEntry < Spree::Base | |||
|
|||
# Fix for https://github.com/spree/spree/issues/1767 | |||
# If a payment fails, we want to make sure we keep the record of it failing | |||
after_rollback :save_anyway | |||
after_rollback :save_anyway, if: Proc.new { !Rails.env.test? } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use proc instead of Proc.new.
There used to be #564, which is a more comprehensive solution to this thing. @jhawthorn What do you think, should we just revive that? |
Have we ever talked about having a second storage mechanism for stuff like this, separate from our AR? We're fighting against our technology with things like the log_entries, and it seems to me it would make more sense to shove it in some kind of document or object storage, its not like we ever actually do anything with it in terms of querying. |
(discussed with Reid) An abstracted storage mechanism — in which stores (no pun intended) could choose where to put their spree_log_entries — makes total sense to us. But it seems to me that for core code to dictate a document or object storage, that would expand the (already tight & small) stack requirements for setting up a new Solidus installation. We recognize that this is a small piece of paper mache that covers up a bandage that itself was originally covering up what is (arguably) a code smell. It seems to us the root of the problem is that exceptions (in this case, the rollback) are relied on for too much flow control, which is essentially the root of the code smell. We fully understand this is not a fix to the root of the problem. Also note it can be decorated as the decorated So do with that information what you will. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
We talked a little bit about removing this callback or removing the log entries altogether, but for now this solves a leaky database and I'm always in favour of that.
I am proposing this fix to the
Spree::LogEntry
model.When running my tests with DatabaseCleaner (using
:transaction
), after it asserts my first example usingrspec
, DatabaseCleaner kicks in to transactionally rollback all my test data. Unfortunately, due to this feature, I run into issues where theafter_rollback
is called on theSpree::LogEntry
model which in turn tries to append some information that does not exist anymore since DatabaseCleaner had its way and cleared out my test data. This causes an issue where the record of a variant is not found anymore.For those who use DatabaseCleaner, to ignore trying to create new Spree::LogEntries during test environments. I have attached a gist of a log with a backtrace of my
byebug
statement. Notice at the top of the gist,BEFORE @lpes_calculator; AFTER @lpes_calculator
is wrapped around myexpect
statement.I am open to potentially better solutions.
https://gist.github.com/reidcooper/2e09d5dc21f5783b26d0ae7a633a22f5