openfoodfoundation / openfoodnetwork

Connect suppliers, distributors and consumers to trade local produce.
https://www.openfoodnetwork.org
GNU Affero General Public License v3.0
1.11k stars 719 forks source link

Cart populate error #6422

Open filipefurtad0 opened 3 years ago

filipefurtad0 commented 3 years ago

Description

Errors have been observed lately on the shopfront, while adding items to the cart:

Expected Behavior

Clicking "Add" in the shopfront should not generate errors.

Actual Behaviour

Clicking "Add" in the shopfront sporadically generate the error seen on the video below.

Steps to Reproduce

Question mark... It seems difficult to reproduce:

  1. Log in to an OFN account.
  2. Visit the shopfront of an open shop
  3. Add items to the cart
  4. If you are reproducing the issue successfully you should see a red banner as in the video "There was a problem adding this product to your basket..."

Animated Gif/Screenshot

image

Workaround

Refreshing the page seems to solve the issue.

Severity

Raising this as an S2-bug for awareness/investigation.

Your Environment

Possible Fix

RachL commented 3 years ago

@filipefurtad0 when creating an s2 don't hesitate to move it straight to top of dev-ready right away ;)

lin-d-hop commented 3 years ago

Note when I was testing there was no filter applied.

filipefurtad0 commented 3 years ago

Thanks moving it in there Rachel - forgot that :-)

Updated the issue based on that additional info Lynne :+1:

andrewpbrett commented 3 years ago

I wasn't able to immediately reproduce this in development. I took a look at the code that runs that would return that error message and if I manually added an error during the call to cart_service.populate in the CartController I at least got the matching error message. It seems pretty likely that we're returning on the status: :precondition_failed line. Unfortunately the error message isn't very specific. The two possible reasons for the error (as far as I can tell) are if the database thinks that 1) the order does not have an order cycle set, or 2) the product is not available from the distributor.

There could be something else entirely going on though. So I wrote a pull request https://github.com/openfoodfoundation/openfoodnetwork/pull/6424 to show a more specific error message.

I did notice that when we do the cart population we do some database locking. However, I tried manually raising the lock error class (ActiveRecord::StatementInvalid) in the populate method and that didn't result in the red banner being shown at all, just a silent failure on the backend. So it's probably safe to rule out the locking issues as the culprit.

RachL commented 3 years ago

Update from delivery train on January 18th: this is moved back in all the things. 2 options: