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

ActiveRecord::StaleObjectError in checkout #3238

Closed
kylecrum opened this Issue Jun 20, 2013 · 10 comments

Comments

Projects
None yet
3 participants
@kylecrum
Copy link
Contributor

kylecrum commented Jun 20, 2013

spree_inventory_units has a lock_version column which causes Rails to do optimistic locking. We are seeing in production where it appears that people are submitting data in checkout and then probably submitting it again before the page is finished processing. This is causing Spree to try to destroy objects that it considers stale.

During checkout, it appears as if this line is causing the failure.

@radar

This comment has been minimized.

Copy link
Member

radar commented Jun 26, 2013

This field is as almost as old as old as the Spree repository itself. It took me a while to figure out where this was coming from, and that commit is here: 5089117. (first commit to Spree was in February of the same year

I think we should get rid of the field if there's no documentation about why it's there. Can you confirm that removing this field fixes your issue?

@kylecrum

This comment has been minimized.

Copy link
Contributor

kylecrum commented Jun 26, 2013

@radar , we're going to turn off optimistic locking ActiveRecord::Base.lock_optimistically = false and see if that solves the problem. It's a bit difficult to consistently reproduce so we'll let it bake for a while and monitor any errors.

@radar

This comment has been minimized.

Copy link
Member

radar commented Jun 28, 2013

Ok, sounds good. I think we can look at this issue again in a month's time and see if there's been any problems since you turned it off.

@mrpollo

This comment has been minimized.

Copy link
Contributor

mrpollo commented Jul 11, 2013

Hey guys confirming this is a real issue happening to us as well in production, couldn't cancel an order, tried it with optimistic lock off and it worked great, need help with a PR?

@kylecrum

This comment has been minimized.

Copy link
Contributor

kylecrum commented Jul 11, 2013

@radar @mrpollo We've turned off optimistic locking all together and haven't had the error since. Checkout process and everything else seems to work as expected.

A PR should just consist of a migration dropping the lock_version column on spree_inventory_units .

@mrpollo

This comment has been minimized.

Copy link
Contributor

mrpollo commented Jul 11, 2013

@radar got it fixed here mrpollo@09fe7e1

@mrpollo

This comment has been minimized.

Copy link
Contributor

mrpollo commented Jul 11, 2013

@radar disregard the comment above :)
@kylecrum removed my commit per your comments, I rushed to get a solution here is the newer commit

mrpollo@bddebc7

@kylecrum

This comment has been minimized.

Copy link
Contributor

kylecrum commented Jul 11, 2013

@mrpollo cool. Did you create a PR?

@mrpollo

This comment has been minimized.

Copy link
Contributor

mrpollo commented Jul 11, 2013

@kylecrum I just did

@radar

This comment has been minimized.

Copy link
Member

radar commented Jul 11, 2013

Awesome, thanks for the confirmation @mrpollo. I'll pull in that PR now.

@radar radar closed this in d2a9cdf Jul 12, 2013

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