Magento2: It's possible to create multiple products with the same SKU

Created on 21 Oct 2016  路  16Comments  路  Source: magento/magento2

Preconditions

This issue exists in current HEAD in the develop branch (0c6227d2c0b68f55bc1d7fb0e878a3c597b50653). The bug is very apparent from looking at the code. The environment is irrelevant to the issue.

Steps to reproduce

Save a non-existent product more than once simultaneously (e.g. via the REST API).

Expected result

For all but the "winning" save operation (i.e. the one which reaches the database first), either an exception should be raised or updates should be made to the product which was created by the "winning" save operation.

Actual result

Either:
Multiple products are created with the same SKU.
Or:
Multiple products are created with different SKUs (a number is appended to the end of the SKU to make it unique). THIS IS REALLY BAD! If the application detects a duplicate SKU when creating a product then this should be an error! It is critical that products are created with the actual SKU a business uses, and not some other meaningless SKU.

The cause of this issue is very clear when looking at the code [1] [2]. SKU uniqueness is enforced within the application code but not by a constraint in the database. This is totally not robust enough for an application of Magento's importance. Please add database constraints to enforce SKU uniqueness and remove this damaging _generateUniqueSku() method [1].

[1] [Uniqueness is enforced in application code](https://github.com/magento/magento2/blob/0c6227d2c0b68f55bc1d7fb0e878a3c597b50653/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Sku.php#L99)
[2] [There is no uniqueness constraint in the database schema for SKU](https://github.com/magento/magento2/blob/0c6227d2c0b68f55bc1d7fb0e878a3c597b50653/app/code/Magento/Catalog/Setup/InstallSchema.php#L93)

FrameworWebapi WroCD dmcdindia1 Confirmed Format is valid Ready for Work Reproduced on 2.1.x Reproduced on 2.2.x Reproduced on 2.3.x bug report

Most helpful comment

Hi there

All 16 comments

Hi, thank you for your report. Internal issue MAGETWO-61468 is created.

Issue in progress @sinisa86

I am working on this issue.

@joshdifabio, thank you for your report.
We've created internal ticket(s) MAGETWO-61468, MAGETWO-62571 to track progress on the issue.

Hi there

mageconf

@dimaperedriy did you start to work on this issue?

distributed-cd

@mrodespin Hello, do you still work on this issue?

Hi, everybody on #WroCD :)
This issue looks good

WroCD

@wokisajn thank you for joining. Please accept team invitation here and self-assign the issue.

WroCD

@ecomchallenger thank you for joining. Please accept team invitation here and self-assign the issue.

I am working on this at #dmcdindia1

i have run product add script simultaneously but unable to reproduce this issue in magento 2.3

Was this page helpful?
0 / 5 - 0 ratings