-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
Duplicate products with identical SKUs created via API #27295
Comments
Issue-Label Bot is automatically applying the label Links: app homepage, dashboard and code for this bot. |
Thank you for raising the issue! However, I can't reproduce it on my end. I make the following POST request to
As a result, I only get 1 product created as expected: And here is to show that if SKUs are indeed unique in 2 products, both products get created as expected as well: Are you still able to reproduce the issue you are having? |
As a part of this repository’s maintenance, I am closing this issue due to inactivity. Please feel free to comment on it in case we missed something. We’d be happy to take another look. |
Hi @juliaamosova, Your test in Postman is wrong. It creates multiple products using one request. This works fine. I specifically wrote that you can create multiple products with identical SKUs by making multiple API requests at the same time. In order to reproduce that issue, you need to use curl as in my Steps to reproduce example above. |
|
Thank you for your follow-up @rafal-sokolowski. I am reopening this issue to take a look at it again in a bit. |
@juliaamosova @rafal-sokolowski I have been dealing with this issue for months now and it drives me crazy. I first found this in October when a customer called about having thousands of duplicated and even quadruplicated products in draft and thought it was my script.
I have designed my own mechanism that takes my customer's CRM data and sends them as batches (create / update) of 5 to their website via synchronization either every 20 minutes or immediate execution depending on customers' needs. The problem takes place when they leave it running for hours. Do you think scheduled transients play some role in all this nightmare, that is, does it intervene for some reason and interrupts the whole process? |
@juliaamosova @rafal-sokolowski this is to verify that I have managed to reproduce your bug by following your aforementioned steps: WordPress EnvironmentWordPress address (URL): https://local.demo Server EnvironmentServer Info: nginx/1.16.1 |
This looks like race condition because |
any update on this? I'm facing the same issue. |
I'm running multiple Redis queues and it bypasses the SKU validation occasionally. |
Any Update? Still facing this issue. @vedanshujain |
Is there an update to this bug? Still have this issue @vedanshujain |
No update yet, unfortunately. This will take a while to resolve, unfortunately. |
Using C#, we sync products from a different platform to WooCommere with API. We had this problem too, when we saw that there was no solution, we saved the day with an alternative method.
(my english is not very well and I'm sorry about that.) |
I have the same problem with wordpress 5.9 and woocommerce 6.2.0. maybe if we can add the sku as a unique field in the mysql database can resolve the problem? |
Having same issue. When uploading 15000 products via api, it seems to be duplicating some of them. |
Is there an update on this bug yet? @vedanshujain |
I believe the problem is the images size uploaded on the process on creating the product, |
Any updates? |
Anyone found a solution yet? |
When I compressed the product images the problem went away, |
Thank you... |
On the woocommerce side of things, the only solution would be to create a lock on the process to prevent the race condition, and queue up any additional incoming requests. On the application side of things, managing concurrency issues or providing your own sku creation algorithm would be prevent this error from happening. This is what I do in my .net/c# application. |
What I don't understand about your situation is why you are duplicating the request. Can you not prevent this from happening in your code? Both of your requests claim to be unique sku products, however, it's obvious that is not the case. Prevent the duplicate request by ensuring your list of requests are truly unique. Problem solved. |
@richardaubin For the same reason you have a lock on your door. You can ask for no one to break in, but that's unlikely to work. I agree that if you are the one controlling the data being pushed to the WooCommerce API, you can easily fix the problem. However, the scenario I described is when it's a third-party solution that generates those requests, and you can't do anything about it except for asking other developers to fix it, which may never happen. Problem unsolved. |
Any updates? |
Hey folks! we have an update regarding this issue. We have this PR #47476, which is proposed to fix this. NOTE: This fix only works for fresh product creation not for updates, so its best you try it on a fresh site or with a new set of products and skus. Let us know if you face any issues or fatals. |
Please test it with this zip, updated a few things: woocommerce.zip |
Description of the problem
The syncing system sends requests to
/wp-json/wc/v3/products/batch
endpoint. It usually creates concurrent connections to the WooCommerce API. Sometimes, it happens that if two or more requests contain information about the same product and they run at the same time we end up with multiple products created having identical SKUs.Steps to reproduce
Expected behavior
By default, it should not be possible to add a new product with an existing SKU.
Isolating the problem (mark completed items with an [x]):
WordPress Environment
The text was updated successfully, but these errors were encountered: