Skip to content
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

Integrity constraint violation when syncing order #40

Open
GaryReckard opened this issue Jan 22, 2021 · 2 comments
Open

Integrity constraint violation when syncing order #40

GaryReckard opened this issue Jan 22, 2021 · 2 comments

Comments

@GaryReckard
Copy link

We've been having an elusive, recurring issue in our Craft Commerce store where amongst thousands of successful orders, the occasional few will have an issue where our custom code that should fire on EVENT_AFTER_ORDER_PAID does not get executed, so the order does not get sent to our shipping partner.

The common thread that I have found is that the following error shows in the logs right after our custom code for EVENT_AFTER_COMPLETE_ORDER executes:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '6326993' for key 'PRIMARY'
The SQL being executed was: INSERT INTO `craft_mc_orders_synced` (`orderId`, `isCart`, `lastSynced`) VALUES (6326993, 0, '2021-01-21 05:58:55')

Whatever is causing this error, it's preventing a small number of our orders to not get shipped out, until we catch the error.

Any idea why this might be happening, how to prevent it, or at the very least prevent it from derailing the rest of the events that should fire after it?

Thanks!

We're on Mailchimp-Commerce v1.2.2 and Craft 3.4.25.

@rsanchez
Copy link

Seems like a race condition, which can be triggered if you manually save orders in code. Might I recommend using an upsert query in the _createOrder method rather than a plain insert query? Yii does have an upsert helper: https://www.yiiframework.com/doc/api/2.0/yii-db-command#upsert()-detail

@GaryReckard
Copy link
Author

Hi again! Any chance this 'upsert' suggestion could be implemented in an updated version of this plugin? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants