Data ConcurrencyException when updating multiple deliveries to Delivered

Hi,

In an integration for shippments I get shippments for several orders and when some orders has been processed I get below Concurrency error, and the site restarts.

The error occures within:
delivery.SetDeliveryStatus((short)DeliveryState.Delivered, securityToken);

The delivery status is updated, the Payment is captured, but the orderstatus is not updated to completed.
When running the same order again, it works.

—Error—
Exception in Litium appId=/LM/W3SVC/1/ROOT type=Litium.Foundation.Modules.ECommerce.Data.ConcurrencyException message=Delivery (db9f64c1-1a12-4973-82be-6597aaf420f1) has already been changed in the database. Get a new copy of the object and submit your changes again. stack= at Litium.Foundation.Modules.ECommerce.Data.DeliveryDataProvider.Update(DeliveryCarrier carrier, SqlCommand openCommand) at Litium.Foundation.Modules.ECommerce.Data.DeliveryDataProvider.Update(DeliveryCarrier carrier) at Litium.Foundation.Modules.ECommerce.Deliveries.Delivery.UpdateFromCarrier(DeliveryCarrier carrier, SecurityToken token) at Litium.Foundation.Modules.ECommerce.StateTransitionSystem.FiniteStateMachine1.UpdateDatabase(CarrierType carrier, UpdateFromCarrierHandler updateFromCarrier, SecurityToken token) at Litium.Foundation.Modules.ECommerce.StateTransitionSystem.FiniteStateMachine1.TransitionAction(StateTransition1 stateTransition, CarrierType carrier, UpdateFromCarrierHandler updateFromCarrier, SecurityToken token) at Litium.Foundation.Modules.ECommerce.StateTransitionSystem.FiniteStateMachine1.TransitionAction(Int16 nextStateId, CarrierType carrier, UpdateFromCarrierHandler updateFromCarrier, SecurityToken token) at Litium.Foundation.Modules.ECommerce.Deliveries.Delivery.SetDeliveryStatus(Int16 state, SecurityToken token) at Litium.Accelerator.Tasks.FetchShipmentNumberTask.d__5.MoveNext() in C:\projects\posterton\Src\Litium.Accelerator\Tasks\FetchShipmentNumberTask.cs:line 76 — End of stack trace from previous location where exception was thrown — at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch()

Hello… “jenni73” :innocent:,

Do you update the order as well close to this code? If so in what order do you update your entities (order and delivery)?

Halloj Martin;)

No, I update the delivery with:
delivery.SetActualDeliveryDate(DateTime.Now, securityToken);
delivery.SetTrackingUrl(shipmentNumber, securityToken);
delivery.SetDeliveryStatus((short)DeliveryState.Delivered, securityToken);

When the error occur, ActualDeliveryDate and TrackingUrl is set and:
DeliveryStatus=Delivered, PaymentStatus=Paid but Orderstatus=Processing(as before the job starts)

When everything works, after SetDeliveryStatus, DeliveryStatus= Delivered, PaymentStatus=Paid, Orderstatus=Complete.

I do not update the order directly in this job, only via the delivery.
//J

Do the update with the carrier instead, something like

var carrier = delivery.GetAsCarrier();
carrier.ActualDeliveryDate = DateTime.Now;
carrier.TrackingUrl = shipmentNumber;
delivery.SetValuesFromCarrier(carrier, securityToken);
delivery.SetDeliveryStatus((short)DeliveryState.Delivered, securityToken); // Should be executed after the values are set, that will invoke state transition engine.
1 Like

Hi @patric.forsgard,
I still get the problem with ConcurrencyException with the code
var deliveryCarrier = delivery.GetAsCarrier();
deliveryCarrier.ActualDeliveryDate = DateTime.Now;
deliveryCarrier.TrackingUrl = shipmentNumber;
delivery.SetValuesFromCarrier(deliveryCarrier, securityToken);

                delivery.SetDeliveryStatus((short)DeliveryState.Delivered, securityToken);

it looks like the problem only occurs with Klarna V3 payment provider, and when running in a Try-Catch statement, the next order works, if its not Klarana V3.

My Conclusion is that Klarna does something within the delivery.SetDeliveryStatus((short)DeliveryState.Delivered, securityToken) statemend, like sets the deliverystatus to something else first, it does the capture and then tryes to set de delivery to delivered…

however the problem remains :frowning: