-
Notifications
You must be signed in to change notification settings - Fork 9.4k
integrity constraint violation in sales_clean_orders cron job #27918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @ktruehl. Thank you for your report.
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
For more details, please, review the Magento Contributor Assistant documentation. @ktruehl do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?
|
The |
@magento give me 2.4-develop instance |
Hi @CarmineDamore78. Thank you for your request. I'm working on Magento 2.4-develop instance for you |
Hi @CarmineDamore78, here is your Magento instance. |
Hi @ktruehl I wasn't enable to reproduce the issue on M2.4 develop and M.2.3.4 Thanks |
Hi @CarmineDamore78, You won't be able to reproduce the issue on a Magento instance that lasts only 3 hours. The default setting for the delay for cleaning out orders is 8 hours. So you would have to create an order, wait for at least 8 hours without touching the order, then check the result of the |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions! |
I have the same issue on Magento version 2.4.1
The main problem in it. When we placed an order as a guest user method updateCustomerRuleUsages doesn't execute and doesn't create new record in salesrule_customer table. |
Preconditions (*)
Steps to reproduce (*)
pending_payment
status works.pending_payment
status.sales_clean_orders
cron job to process this order.Expected result (*)
sales_clean_orders
runs smoothly and the unfinished order should now be cancelled.Actual result (*)
sales_clean_orders
runs into an exception:Observations and Fix
The problem lies in the class
Magento\SalesRule\Model\Coupon\UpdateCouponUsages
in methodupdateCustomerRuleUsages()
. The problem occurs if no sales rule/customer relation ($ruleCustomer
) exists ($ruleCustomer->getId() == false
) and if$increment == 0
. In that case the method will try to save the sales rule/customer relation$ruleCustomer
without any data being set on it. In particular the fieldrule_id
will benull
, which than causes the foreign key constraint violation.The problem can be easily fixed by adding an
else
clause to theif/elseif
instruction:This will cause the sales rule/customer relation to not be saved.
The text was updated successfully, but these errors were encountered: