Skip to content

REFERENCE constraint error when running cart cleanup #781

@nickfrederiksen

Description

@nickfrederiksen

Which component is this issue related to?

Umbraco Commerce (Core)

Which Umbraco Commerce version are you using? (Please write the exact version, example: 10.1.0)

15.3.13

Bug summary

When the cart clean up task starts, it fails with a reference constraint error on the constraint: FK_umbracoCommerceOrderTransactionActivity_umbracoCommerceOrder

Specifics

We have this error message in our log:

Microsoft.Data.SqlClient.SqlException (0x80131904): The DELETE statement conflicted with the REFERENCE constraint "FK_umbracoCommerceOrderTransactionActivity_umbracoCommerceOrder". The conflict occurred in database "[REDACTED]", table "dbo.umbracoCommerceOrderTransactionActivity", column 'orderId'.
The statement has been terminated.
   at Umbraco.Commerce.Infrastructure.Resiliency.PollyExecutionStrategyBase.ExecuteAsync[TResult](Func`2 operation, Func`2 verifySucceeded, CancellationToken cancellationToken)
   at Umbraco.Commerce.Core.Services.OrderCleanupService.DeleteCartsOlderThanDaysAsync(Guid storeId, Int32 days, CancellationToken cancellationToken)
   at Umbraco.Commerce.Cms.Scheduling.CartCleanupHostedService.PerformExecuteAsync(Object state)
   at Umbraco.Cms.Infrastructure.HostedServices.RecurringHostedServiceBase.ExecuteAsync(Object state)
ClientConnectionId:339a085d-905a-47c5-ae09-8a8e50e5a0dd
Error Number:547,State:0,Class:16
ClientConnectionId before routing:6290a944-583d-4c9f-b950-9c47502290e0
Routing Destination:[REDACTED]

Steps to reproduce

Enable cart cleanup using this config and wait for it to run:

"Umbraco": {
	"Commerce": {
		"CartCleanupPolicy": {
			"EnableCleanup": true,
			"KeepCartsForDays": 60,
			"FirstRunTime": "* 4 * * *",
			"Period": "1.00:00:00"
		}
	}
}

Expected result / actual result

Old, abandoned, carts are removed.

Dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions