umbraco / Umbraco.Commerce.Issues

18 stars 2 forks source link

DBConcurrencyException: A Concurrency update occurred in table 'umbracoCommerceOrder' for primary key value #572

Open DynamicDave opened 1 day ago

DynamicDave commented 1 day ago

When trying to delete a orderline from the order/cart we get the following error message:

DBConcurrencyException: A Concurrency update occurred in table 'umbracoCommerceOrder' for primary key value(s) = 'e541f8f0-13d4-4d37-b2bd-0192ae1c32bd' and version = '14' Umbraco.Commerce.Infrastructure.Resiliency.PollyExecutionStrategyBase.Execute<TResult>(Func<TResult> operation, Func<ExecutionResult<TResult>> verifySucceeded) Umbraco.Commerce.Core.UmbracoCommerceUnitOfWorkProvider.Execute(IUnitOfWorkOptions options, Action<IUnitOfWork> action) Umbraco.Commerce.Core.UmbracoCommerceUnitOfWorkProvider.Execute(Action<IUnitOfWork> action) Primex_Whitelabel_Webshops.Controllers.CartController.RemoveFromCart(RemoveFromCartDto postModel) in CartController.cs + _umbracoCommerceApi.Uow.Execute(uow => { lambda_method1480(Closure , object , object[] ) Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync() Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync() Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()

Steps To Reproduce

  1. Add something to your cart
  2. Add something else to your cart
  3. Click on 'remove from cart' for one of the items
  4. See error

Additional context This is the 'remove from cart' code:

public IActionResult RemoveFromCart(RemoveFromCartDto postModel) { try { _umbracoCommerceApi.Uow.Execute(uow => { var store = CurrentPage.GetStore(); var order = _umbracoCommerceApi.GetOrCreateCurrentOrder(store.Id) .AsWritable(uow) .RemoveOrderLine(postModel.OrderLineId); _umbracoCommerceApi.SaveOrder(order); uow.Complete(); }); } catch (ValidationException ex) { ModelState.AddModelError("productReference", "Failed to remove cart item"); return CurrentUmbracoPage(); } return RedirectToCurrentUmbracoPage(); }

Umbraco Commerce version: v13.1.8

If anyone knows a solution; it would be greatly appreciated!

mattbrailsford commented 1 day ago

Do you have any notification handlers that are also attempting to update the order? Are you able to replicate this on the demo store? https://github.com/umbraco/Umbraco.Commerce.DemoStore