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

Load previously lost decorator code and don't delete orders #5905

Merged
merged 10 commits into from Aug 21, 2020
Merged

Load previously lost decorator code and don't delete orders #5905

merged 10 commits into from Aug 21, 2020

Conversation

mkllnk
Copy link
Member

@mkllnk mkllnk commented Aug 14, 2020

What? Why?

While investigating #5897 I found some code that could accidentally delete an order. But then I found that the code wasn't loaded and could not have caused a disappearing order.

I continued to investigate the issue of unloaded code because it could be responsible of many random issues. The deeper I dug, the clearer I could see that the unloaded code was mostly insignificant. Nonetheless, I addressed the loading issue and removed the code that could delete orders.

The non-loading was mostly no issue because our code didn't change Spree's logic. The only exception are the changes from 20f610f which were lost since v3 and now brought back.

What should we test?

Parallel browsing
  • As guest user, go to a shop and add items to the cart.
  • Open a different browser (or a private window or a different device) and do the same there with different items in your cart.
  • The two carts should be persisted and independent.
  • Log in with the same user in both browser sessions.
  • Both sessions should keep their individual orders.
  • Go through checkout with the first browser session.
  • The first browser should now show an empty cart again.
  • The second browser should still have its old cart.

Release notes

When shopping with multiple devices, no carts are lost.

Changelog Category: Changed

How is this related to the Spree upgrade?

During the last Spree update we lost some of our customisations. They were simply not loaded. Now we are loading those customisations again, enabling us to customise more and getting rid of Spree.

When we imported and merged Spree's controller modules with our
decorators, Rails started using Spree's original code again.

This was first included in v3.2.0 and deployed on 28 July 2020.
We used to delete old cart orders so that they wouldn't re-appear after
a successful checkout of another order. Keeping them ensures that we
don't remove an order that is still used by another device. It also
makes sure that we keep references of failed payments.
@mkllnk mkllnk self-assigned this Aug 14, 2020
We changed some of Spree's logic and want to use that. And once we
remove the spree_core gem, we need to load those files before using
them.
I was looking for library files that may be used but are not loaded.
I would then add the missing `require` statements. But I found that this
module isn't used any more.

Usage removed in:
310d1b3
Also removing related unused classes and their specs.
We didn't actually change any logic in our version of the Spree
environment file but if we do that in the future, we want to be sure
that it takes effect. Our file was ignored and not loaded before.
@mkllnk mkllnk marked this pull request as ready for review August 14, 2020 06:55
@mkllnk mkllnk marked this pull request as draft August 14, 2020 06:56
Copy link
Contributor

@Matt-Yorkley Matt-Yorkley left a comment

Choose a reason for hiding this comment

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

Great investigation! Hopefully this will help with these mercurial checkout issues...

Copy link
Contributor

@luisramos0 luisramos0 left a comment

Choose a reason for hiding this comment

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

Brilliant detective work @mkllnk thanks a lot!
Why draft? Looks good for testing.

spec/lib/spree/core/environment_spec.rb Show resolved Hide resolved
app/controllers/base_controller.rb Outdated Show resolved Hide resolved
@luisramos0
Copy link
Contributor

luisramos0 commented Aug 16, 2020

Note: on all investigations I have done related to failed payments I only found missing entries on spree_payments. spree_orders were always there. So:

  • option 1 - the payments issues I investigated are different from Stripe payment fails but no record in OFN #5897 where the order is missing
  • option 2 - the order.destroy that we are removing here could, in some cases, destroy the payments but not the order?

I'd say option 1 is more likely and this is a different problem from the problem we have tried to fix in #5806 for example.

@luisramos0
Copy link
Contributor

I'd mark this as closing #5897 💪
I'd merge this, close #5897 and then reopen 5897 if we do have any other occurrences.

@luisramos0
Copy link
Contributor

luisramos0 commented Aug 16, 2020

I think this could also have an impact on #5862
I think we need to get this PR in the next release (not the current release to be tested Monday and deployed on Tuesday), ideally merge before this Thursday.

@mkllnk
Copy link
Member Author

mkllnk commented Aug 18, 2020

Thanks for your early review. I'll continue my work today. I should have mentioned on Friday that I left it as draft because I didn't verify all my claims. I didn't go through the testing steps myself, they are just guesses from what I saw in the code. At the weekend, I also remembered that some controllers did load the helper file (CartController and Spree::OrdersController). So the deletion of old carts could have happened when logging in on the cart page, maybe? I'll try to replicate.

@luisramos0
Copy link
Contributor

ok 👍
Will you manage to finish this tomorrow?
I think this PR, as is, can fix the bug and is harmless so I think we should go ahead with it in this weeks release 👍

@luisramos0
Copy link
Contributor

Hey @mkllnk I think now I remember in delivery train meeting you suggesting I pick this one up so you can work on mobile?
I am correct?
If so, what exactly do you think still needs to be done here? Can we just move this to Test Ready?

Every page load creates a cart order if none is present. So when a user
logs in, they always have an order stored in their session. And
therefore, we never got to recover an old order.

We could have fixed the code to restore old orders. But as far as I can
tell, order recovery hasn't been working for years and I couldn't find
any issue requesting this feature.

If we wanted to implement order recovery, it should probably be designed
more carefully and included in the `current_order` method.
@mkllnk
Copy link
Member Author

mkllnk commented Aug 19, 2020

I needed to verify the test instructions and found that one part of it was invalid. I added another two commits, addressing your feedback, @luisramos0, and removing the dead code. There is more I can clean up but I will do that in a separate PR.

@mkllnk mkllnk marked this pull request as ready for review August 19, 2020 02:08
@mkllnk mkllnk requested a review from luisramos0 August 19, 2020 02:09
@mkllnk
Copy link
Member Author

mkllnk commented Aug 19, 2020

@luisramos0 I added two more commits in a separate PR: #5927 If you think it's better to include them here and we can still make it for the release, that would be awesome but I didn't want to put anything in the way of this PR getting into the release.

This reverts commit 355c5f5.

This code is necessary to preserver cart contents across logins on
different browser sessions.
@filipefurtad0 filipefurtad0 self-assigned this Aug 19, 2020
@filipefurtad0 filipefurtad0 added pr-staged-es pr-staged-uk staging.openfoodnetwork.org.uk pr-staged-fr staging.coopcircuits.fr and removed pr-staged-uk staging.openfoodnetwork.org.uk pr-staged-es labels Aug 19, 2020
@filipefurtad0
Copy link
Contributor

filipefurtad0 commented Aug 20, 2020

Hi @mkllnk ,

Thanks for this investigation and the detailed testing-steps!

Since master branch appears to be broken (as discussed here), I have staged the build used for release testing (v3.2.3), before testing this PR. The images below show session 1 on (the left) and session 2 (on the right side). I followed your procedure:

i) As guest user, went to a shop and added 5 items to the cart.
ii) Repeat the step above, on a different browser/private window. (I found no to play a role, if they are the same items or not)

At this point, both guest sessions have 5 items each. Proceeded:

iii) Logged in with the same user in both sessions

Here it became clear, that the condition
"- Both sessions should keep their individual orders." - is not verified.

The second session, now contains 10 items, the items from session 1 plus its own:

image

iv) At this point, attempting to checkout on session 1 generates the error:

image

So,

  • "The first browser should now show an empty cart again." - is not verified
  • "The second browser should still have its old cart." - it still does, but it contains the items from session 1 as well.

v) checking out with session 2 (which contains 10 items) is possible.

After staging the PR, following steps i) to iii), leads to the same result as before:

image

It's possible to check what's in the cart for both sessions - session 2 (right) contains the items from session 1 as well. Also, and as before, it's not possible to check out from session 1; This is only possible for session 2.

So, I could not verify the test cases and I am not sure the PR introduces a benefit. Thoughts? (adding feedback label)

Another issue found, before and after the PR, and therefore unrelated:

After step iii), if instead of attempting to checkout one attempts to:

  • go back to the cart on session 1 -> a redirection to the homepage occurs
  • after this, trying to checkout on session 2 is not possible, and the error "Checkout Failed. Let us know so we can process your order" is seen.

At this point, the user has items in the cart, but cannot checkout. He cannot visit /cart page - gets redirected to the homepage
Trying to visit another shop leads to the grumpy cat:

image

Logging out and back in does not solve the issue, so basically, this account becomes blocked, in terms of customer function. This will need an issue, as it seems like a point of no return, for the user.

Respective bugsnag error:
https://openfoodnetwork.slack.com/archives/CEF14NU3V/p1597934757001500

@filipefurtad0 filipefurtad0 added feedback-needed and removed pr-staged-fr staging.coopcircuits.fr labels Aug 20, 2020
@luisramos0
Copy link
Contributor

Hmmm, the interesting thing is that all this is before you stage this PR!

This PR does remove the logic of merging orders so my question is: what happens to this test case after the PR. I think it will be better! Can you please try?

@luisramos0
Copy link
Contributor

"The two carts should be persisted and independent." this is not correct without the last commit I reverted.
When you log in to the new session your cart should be there as it was on the other session.

@filipefurtad0
Copy link
Contributor

filipefurtad0 commented Aug 20, 2020

Hey @luisramos0,

I ran the tests before and after the PR, and got the same results... Also the issue found applies to before/after (I double checked this). It's quite a lot of text, sorry - it's easy to miss... I've edited it for readability.

I also tried the test case you proposed:

  • login to OFN and add something to the cart.
  • Then, open an icognito tab and login again, do you see your cart as it was? -> Yup, this worked! 👍 also before and after the PR.

So basically, I could not reproduce the scenario "lose carts", when shopping in different sessions.

@luisramos0
Copy link
Contributor

luisramos0 commented Aug 21, 2020

ok, we need to move this forward today to get into the release.
I think this PR is low risk.
I am not sure about the test steps for this PR but this calls for a "standard test plan" on concurrent sessions and carts before and after login.
So, if you make your tests around this subject and see this PR is not introducing any new problems (the problem above is preexisting so I think we should create a new issue and ignore in terms of this PR), I think we should merge it.

What do you think Filipe?

@luisramos0
Copy link
Contributor

luisramos0 commented Aug 21, 2020

ok, I talked with Filipe about this on slack.

This is my presentation of the situation:

Talking with Filipe we concluded the best approach here is to merge this PR and include an extra round of verifications related to this in the upcoming release testing process.

@filipefurtad0
Copy link
Contributor

Fully agree @luisramos0 ,
let's merge! 👍

@luisramos0 luisramos0 merged commit d1b60e3 into openfoodfoundation:master Aug 21, 2020
@mkllnk mkllnk deleted the lost-decorators branch August 25, 2020 04:40
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.

None yet

4 participants