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

Created on 4 April 2024, 9 months ago

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.

🐛 Bug report
Status

Active

Version

2.0

Component

Order

Created by

🇺🇸United States nicxvan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @nicxvan
  • 🇮🇱Israel jsacksick

    I think this is caused by Commerce shipping, but not sure how to fix this unfortunately:

    #6 /app/web/modules/contrib/commerce_shipping/src/Plugin/Commerce/CheckoutPane/ShippingInformation.php(349): Drupal\Core\Entity\EntityBase->save()
    

    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?

  • 🇺🇸United States nicxvan

    The 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.

  • I 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}

  • 🇨🇭Switzerland znerol

    I'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

    [commerce_order] [error] <pre>Drupal\commerce_order\Exception\OrderVersionMismatchException: Attempted to save order NNNNNN with version 6. Current version is 7. in modules/contrib/commerce/modules/order/src/Entity/Order.php:719
    Stack trace:
    #0 core/lib/Drupal/Core/Entity/EntityStorageBase.php(528): Drupal\commerce_order\Entity\Order->preSave(Object(Drupal\commerce_order\OrderStorage))
    #1 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(753): Drupal\Core\Entity\EntityStorageBase->doPreSave(Object(Drupal\commerce_order\Entity\Order))
    #2 core/lib/Drupal/Core/Entity/EntityStorageBase.php(483): Drupal\Core\Entity\ContentEntityStorageBase->doPreSave(Object(Drupal\commerce_order\Entity\Order))
    #3 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(806): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\commerce_order\Entity\Order))
    #4 modules/contrib/commerce/modules/order/src/OrderStorage.php(169): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\commerce_order\Entity\Order))
    #5 core/lib/Drupal/Core/Entity/EntityBase.php(354): Drupal\commerce_order\OrderStorage->save(Object(Drupal\commerce_order\Entity\Order))
    #6 modules/contrib/commerce_shipping/src/Plugin/Commerce/CheckoutPane/ShippingInformation.php(310): Drupal\Core\Entity\EntityBase->save()
    #7 modules/custom/custom_retail_checkout/src/Plugin/Commerce/CheckoutPane/RetailShippingInformation.php(23): Drupal\commerce_shipping\Plugin\Commerce\CheckoutPane\ShippingInformation->buildPaneForm(Array, Object(Drupal\Core\Form\FormState), Array)
    #8 modules/contrib/commerce/modules/checkout/src/Plugin/Commerce/CheckoutFlow/CheckoutFlowWithPanesBase.php(546): Drupal\custom_retail_checkout\Plugin\Commerce\CheckoutPane\RetailShippingInformation->buildPaneForm(Array, Object(Drupal\Core\Form\FormState), Array)
    #9 [internal function]: Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowWithPanesBase->buildForm(Array, Object(Drupal\Core\Form\FormState), 'order_informati...')
    #10 core/lib/Drupal/Core/Form/FormBuilder.php(536): call_user_func_array(Array, Array)
    #11 core/lib/Drupal/Core/Form/FormBuilder.php(375): Drupal\Core\Form\FormBuilder->retrieveForm('commerce_checko...', Object(Drupal\Core\Form\FormState))
    #12 core/lib/Drupal/Core/Form/FormBuilder.php(633): Drupal\Core\Form\FormBuilder->rebuildForm('commerce_checko...', Object(Drupal\Core\Form\FormState), Array)
    #13 core/lib/Drupal/Core/Form/FormBuilder.php(326): Drupal\Core\Form\FormBuilder->processForm('commerce_checko...', Array, Object(Drupal\Core\Form\FormState))
    #14 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))
    #15 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...')
    #16 [internal function]: Drupal\commerce_checkout\Controller\CheckoutController->formPage(Object(Drupal\Core\Routing\RouteMatch))
    #17 core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
    [...]
    

    I guess the ShippingInformation should use OrderStorage::loadForUpdate() when it is attempting to update shipments on the order.

  • 🇨🇭Switzerland znerol

    Pushed 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.

  • Pipeline finished with Failed
    16 days ago
    Total: 2463s
    #357783
Production build 0.71.5 2024