Describe your bug or feature request.
I am seeing errors in the logs again about mismatched order versions.
Here is the full stack:
Drupal\commerce_order\Exception\OrderVersionMismatchException: Attempted to save order 125081 with version 8. Current version is 9. in /app/web/modules/contrib/commerce/modules/order/src/Entity/Order.php:682
Stack trace:
#0 /app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(528): Drupal\commerce_order\Entity\Order->preSave(Object(Drupal\commerce_order\OrderStorage))
#1 /app/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(753): Drupal\Core\Entity\EntityStorageBase->doPreSave(Object(Drupal\commerce_order\Entity\Order))
#2 /app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(483): Drupal\Core\Entity\ContentEntityStorageBase->doPreSave(Object(Drupal\commerce_order\Entity\Order))
#3 /app/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(806): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\commerce_order\Entity\Order))
#4 /app/web/modules/contrib/commerce/modules/order/src/OrderStorage.php(169): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\commerce_order\Entity\Order))
#5 /app/web/core/lib/Drupal/Core/Entity/EntityBase.php(352): Drupal\commerce_order\OrderStorage->save(Object(Drupal\commerce_order\Entity\Order))
#6 /app/web/modules/contrib/commerce_shipping/src/Plugin/Commerce/CheckoutPane/ShippingInformation.php(349): Drupal\Core\Entity\EntityBase->save()
#7 /app/web/modules/contrib/commerce/modules/checkout/src/Plugin/Commerce/CheckoutFlow/CheckoutFlowWithPanesBase.php(546): Drupal\commerce_shipping\Plugin\Commerce\CheckoutPane\ShippingInformation->buildPaneForm(Array, Object(Drupal\Core\Form\FormState), Array)
#8 [internal function]: Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowWithPanesBase->buildForm(Array, Object(Drupal\Core\Form\FormState), 'order_informati...')
#9 /app/web/core/lib/Drupal/Core/Form/FormBuilder.php(536): call_user_func_array(Array, Array)
#10 /app/web/core/lib/Drupal/Core/Form/FormBuilder.php(375): Drupal\Core\Form\FormBuilder->retrieveForm('commerce_checko...', Object(Drupal\Core\Form\FormState))
#11 /app/web/core/lib/Drupal/Core/Form/FormBuilder.php(633): Drupal\Core\Form\FormBuilder->rebuildForm('commerce_checko...', Object(Drupal\Core\Form\FormState), Array)
#12 /app/web/core/lib/Drupal/Core/Form/FormBuilder.php(325): Drupal\Core\Form\FormBuilder->processForm('commerce_checko...', Array, Object(Drupal\Core\Form\FormState))
#13 /app/web/core/lib/Drupal/Core/Form/FormBuilder.php(224): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\MultistepDefault), Object(Drupal\Core\Form\FormState))
#14 /app/web/modules/contrib/commerce/modules/checkout/src/Controller/CheckoutController.php(143): Drupal\Core\Form\FormBuilder->getForm(Object(Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\MultistepDefault), 'order_informati...')
#15 [internal function]: Drupal\commerce_checkout\Controller\CheckoutController->formPage(Object(Drupal\Core\Routing\RouteMatch))
#16 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#17 /app/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#18 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#19 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#20 /app/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#21 /app/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#22 /app/web/modules/contrib/redirect_after_login/src/RedirectMiddleware.php(44): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /app/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Drupal\redirect_after_login\RedirectMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /app/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /app/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /app/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /app/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /app/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 /app/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 /app/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#31 /app/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#32 /app/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#33 /app/web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#34 /app/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#35 {main}
If a bug, provide steps to reproduce it from a clean install.
I still do not have a consistent way to reproduce this, but it is still happening occasionally and now there is more information in the error.
This is the location being called: /checkout/125081/order_information?_wrapper_format=drupal_ajax&ajax_form=1
I suspect it a has to do with something when selecting the shipping or payment method.
| Comment | File | Size | Author |
|---|---|---|---|
| #22 | 3438654-save-order-with-incorrect-version-22.patch | 28.35 KB | grevil |
Issue fork commerce_shipping-3438654
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jsacksick commentedI think this is caused by Commerce shipping, but not sure how to fix this unfortunately:
Perhaps we should have a try catch and reload the order when this happens. Are the order mismatch exceptions just logged? Or is an actual exception thrown?
Comment #3
nicxvan commentedThe logs only show what I have shown here, however, I think that the root cause is here: #3282729: Always use checkout cart as main.
What is happening is that if a user has multiple carts and logs in during the checkout process many times the order that they are checking out is the one that gets combined into the other cart. This shuffle is causing several bugs one of which is this exception.
Other issues it is causing:
The user is on a checkout on a cart that technically no longer exists so they cannot continue to review.
Google tag throws exceptions for trying to remove items from a cart that no longer exists.
I'm happy to work on the approach you discussed if you can point me where to start.
Comment #4
99gs3 commentedI am seeing this error.
Previous reports were closed as due to having custom codes and could not be resolved.
Current stack trace are not showing any custom code in the error.
I agree with the plausibility that when customer logs in during the check out process causing the error as I see a USER log entry for session opened just prior to this commerce_order error log
In checkout flow, there is an option to "Assign an anonymous order to a pre-existing user
If the email associated with the order matches an existing user account, the order will be assigned to that account."
Not sure if this has any relevance but it was something that was changed recently.
Drupal\commerce_order\Exception\OrderVersionMismatchException: Attempted to save order 4724 with version 6. Current version is 7. in /public_html/modules/contrib/commerce/modules/order/src/Entity/Order.php:703
Stack trace:
#0 /public_html/core/lib/Drupal/Core/Entity/EntityStorageBase.php(528): Drupal\commerce_order\Entity\Order->preSave()
#1 /public_html/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(753): Drupal\Core\Entity\EntityStorageBase->doPreSave()
#2 /public_html/core/lib/Drupal/Core/Entity/EntityStorageBase.php(483): Drupal\Core\Entity\ContentEntityStorageBase->doPreSave()
#3 /public_html/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(806): Drupal\Core\Entity\EntityStorageBase->save()
#4 /public_html/modules/contrib/commerce/modules/order/src/OrderStorage.php(169): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save()
#5 /public_html/core/lib/Drupal/Core/Entity/EntityBase.php(354): Drupal\commerce_order\OrderStorage->save()
#6 /public_html/modules/contrib/commerce_shipping/src/Plugin/Commerce/CheckoutPane/ShippingInformation.php(349): Drupal\Core\Entity\EntityBase->save()
#7 /public_html/modules/contrib/commerce/modules/checkout/src/Plugin/Commerce/CheckoutFlow/CheckoutFlowWithPanesBase.php(546): Drupal\commerce_shipping\Plugin\Commerce\CheckoutPane\ShippingInformation->buildPaneForm()
#8 [internal function]: Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowWithPanesBase->buildForm()
#9 /public_html/core/lib/Drupal/Core/Form/FormBuilder.php(536): call_user_func_array()
#10 /public_html/core/lib/Drupal/Core/Form/FormBuilder.php(375): Drupal\Core\Form\FormBuilder->retrieveForm()
#11 /public_html/core/lib/Drupal/Core/Form/FormBuilder.php(633): Drupal\Core\Form\FormBuilder->rebuildForm()
#12 /public_html/core/lib/Drupal/Core/Form/FormBuilder.php(326): Drupal\Core\Form\FormBuilder->processForm()
#13 /public_html/core/lib/Drupal/Core/Form/FormBuilder.php(224): Drupal\Core\Form\FormBuilder->buildForm()
#14 /public_html/modules/contrib/commerce/modules/checkout/src/Controller/CheckoutController.php(143): Drupal\Core\Form\FormBuilder->getForm()
#15 [internal function]: Drupal\commerce_checkout\Controller\CheckoutController->formPage()
#16 /public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#17 /public_html/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#18 /public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
#19 /public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#20 /public_html/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#21 /public_html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#22 /public_html/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
#23 /public_html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#24 /public_html/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#25 /public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\ContentLength->handle()
#26 /public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#27 /public_html/modules/contrib/advban/src/AdvbanMiddleware.php(57): Drupal\page_cache\StackMiddleware\PageCache->handle()
#28 /public_html/core/modules/ban/src/BanMiddleware.php(50): Drupal\advban\AdvbanMiddleware->handle()
#29 /public_html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle()
#30 /public_html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#31 /public_html/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#32 /public_html/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#33 /public_html/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#34 /public_html/index.php(19): Drupal\Core\DrupalKernel->handle()
#35 {main}
Comment #5
znerol commentedI'm seeing this occasionally on a production system. In my case it seems related to ajax updates.
Affected URL: example.com/checkout/NNNNNN/order_information?_wrapper_format=drupal_ajax&ajax_form=1
I guess the
ShippingInformationshould use OrderStorage::loadForUpdate() when it is attempting to update shipments on the order.Comment #7
znerol commentedPushed a potential fix. This is intentionally violating coding standards for the sake of reviewability. Should the approach prove to be feasible, the blocks inside the new closures need to be indented properly before merging.
Comment #8
anybodyI can confirm we're seeing the OrderVersionMismatchException error in our logs each day.
Backtrace is similar to the one posted above, so yes this seems to be caused by commerce_shipping in the order information step, by AJAX.
The location logged is:
/checkout/12345/order_information?_wrapper_format=drupal_ajax&ajax_form=1How to proceed here correctly? I'm unsure what this causes for the user?
Adding some related issues.
Comment #13
grevil commented@nicxvan regarding #3, I can (probably) reproduce this, but if you take a look at the examples given here, this is clearly a different issue. And has nothing to do with #3282729: Always use checkout cart as main
- The stack trace from #3282729: Always use checkout cart as main doesn't contain "commerce_shipping"
- The trigger is "/checkout/125081/order_information?_wrapper_format=drupal_ajax&ajax_form=1" which is an ajax call on the order_information form (not the login)
- Atleast for us, the errors are always caused by the anonymous user.
My Steps to reproduce:
- Have "commerce_combine_carts" (and potentially "commerce_add_to_cart_confirmation") enabled
- Login and add a product to the cart.
- Logout
- Add a product to the cart
- Login on checkout
- (Get an unexpected commerce_add_to_cart_confirmation confirmation, press "to cart"[might be a side effect])
- Get the following exception:
This COULD be also a third issue apart from this one and the one mentioned by you, I have to dig deeper tomorrow.
Comment #14
grevil commented@znerol are you using the patch from MR 59 or MR 90 as a patch in production and does it fix the problem for you?
Comment #15
znerol commentedI'm using MR 59 in production.
Comment #16
grevil commentedThanks for the reply @znerol!
@jsacksick what do you think? Both MRs look quite similiar. Only MR 90 is reviewed yet, but MR 59 looks pretty good as well (though it needs rebasing)!
How should we proceed here?
Comment #17
anybodyThe approaches in MR!59 and MR!90 look quite similar, but MR!90 looks a bit cleaner to me. @tbkot can you confirm this also works? @znerol did you also try MR!90?
We'll now implement the feedback from @jsacksick and I think it would be great if anyone here could test if it works and fixes the bug afterwards to get this fixed!
Thanks!
Comment #20
grevil commentedStatic patch of MR90 for the time being.
Comment #21
grevil commentedYea MR 90 is now basically ur original approach @znerol, since we figured out the other doesn't make too much sense in our opinion (getting and directly releasing the order even though it gets later modified in buildPaneForm for example).
Comment #22
grevil commentedAll green!
Static patch applied for the time being.
Comment #23
jsacksick commentedDecided to merge a slightly modified version of #90.
Comment #25
anybodyGreat, thank you very much @jsacksick! FYI: This was not yet merged - unsure if by intent. Sorry for the heads-up then :)