Skip to content
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

Remove after_rollback from LogEntry #2280

Merged
merged 2 commits into from
Oct 20, 2017

Conversation

jhawthorn
Copy link
Contributor

Follow up to #2277 #564

after_rollback has all kinds of problems. When it's run as part of our specs, the filter happens after our spec run (each spec is run inside a transaction), meaning that extra useless blank log entries end up in our database. Gross!

In core's test suite:

config.after(:suite){ p Spree::LogEntry.count } # => 149

I don't think we ever want this, if we were rolling back a log entry, we would also be rolling back a state change on a payment, which is bad.

This is similar to bc19fcb

This is trying to assign the payment's source to source. Not only is
that the wrong thing to do (a payment is the source of a log_entry), but
since it's being built through the payment.log_entries association, it
will have no effect.

Sometimes two wrongs do make a right!
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jasonfb
Copy link

jasonfb commented Oct 12, 2017

we're not quite sure why referencing a source would cause a rollback. All we can think is for the case where payment.source has errors on it, it won't have saved correctly.

this fix seems like it will remove the association between spree_log_entries and payments, which will surely make debugging harder, no?

I'd say a more defensive fix would be

source_id: (!payment.source.new_record?) ? payment.source.id : nil ,

or

source_id: (!payment.source.errors?) ? payment.source.id : nil ,

or even

source_id: (! payment.id.nil?) ? payment.source.id : nil ,

This would eliminate the awkward after_rollback construction but also keep the association (when there really is a payment record to associate)

(keeping the removal of the after_rollback itself)

@jhawthorn
Copy link
Contributor Author

jhawthorn commented Oct 13, 2017

this fix seems like it will remove the association between spree_log_entries and payments, which will surely make debugging harder, no?

This is not being changed here.

@jasonfb
Copy link

jasonfb commented Oct 15, 2017

Oh ok I misunderstood in that case.

@jhawthorn jhawthorn merged commit 88f531a into solidusio:master Oct 20, 2017
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