magento2: MIssing unique key on eav_attribute_label table

Summary (*)

Magento 2.4-develop

The table eav_attribute_label should contain a unique key constraint on the (store_id, attribute_id) pair.
Version:

  • Identified on 2.3.2 Magento Open Source
  • Checked table structure for version 2.2.6, key is still missing.
  • Didn’t check versions prior to 2.2.6, but most probably it has been there since the beginning of time.

Also layered navigation disappears on frontend.

Relates issues: https://github.com/magento/magento2/issues/24581 https://github.com/magento/magento2/issues/24718

Steps to reproduce:

  1. Create a product with any attribute;
  2. Open eav_attribute_label and add a new row with the same attribute_id and store_id values

Screenshot from 2020-11-24 14-30-57

  1. Go to Storefront -> Product page

Actual Result: ✖️ Item with the same id already exists.

Screenshot from 2020-11-24 13-11-13

Expected Result: ✔️ should be notified that duplicate values cannot be created for these fields

Screenshot from 2020-11-24 13-22-27

Examples (*)

One (faulty?) 3rd party extension inserted something in the eav_attribute_label using insertOnDuplicate, but since there is no unique key on the table I ended up with duplicate pairs (store_id, attribute_id). This resulted in “item with id X already exists” error when loading attribute labels

Proposed solution

Add a unique key constraint on the (store_id, attribute_id) pair.

        <constraint xsi:type="unique" referenceId="EAV_ATTRIBUTE_LABEL_ATTRIBUTE_ID_STORE_ID_UNIQUE">
            <column name="store_id"/>
            <column name="attribute_id"/>
        </constraint>

as a bonus, since this is becoming a unique index, the existing index on the store_id, attribute_id pair can be dropped

        <index referenceId="EAV_ATTRIBUTE_LABEL_ATTRIBUTE_ID_STORE_ID" indexType="btree">
            <column name="attribute_id"/>
            <column name="store_id"/>
        </index>

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 25 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Hi @ihor-sviziev,

Sure, I will look into PR and issue comments again and will check it accordingly.

Thank you!

The issue is not reproducible now as mentioned in [comment]( MIssing unique key on eav_attribute_label table).

There is linked PR for this issue which is merged now, so closing this issue now.

Please reopen and update if you wish to continue.

Thank you for your contribution!

Changes that were fixing this issue were reverted in https://github.com/magento/magento2/commit/e1958fece28f2726d2d7cb6a48b1b25cb5b3862e for 2.3.x and https://github.com/magento/magento2/commit/f3d3bce01229df6c47949036bf04921b52ecd6ba for 2.4.0. Re-opening

Hi @gabrieldagama here is quote of my comment why this issue was reopened

Hi @tzyganu. Thank you for your report. The issue has been fixed in magento/magento2#24682 by @KaushikChavda in 2.3-develop branch Related commit(s):

The fix will be available with the upcoming 2.3.4 release.

@engcom-Charlie Steps to what? There are no steps. There is just an explanation. One attribute should only have one single label on one store view. But the eav_attribute_label allows multiple labels for the same attribute for a single store view. This can lead to errors when loading an attribute collection. I know that duplicate labels cannot happen via admin UI, but it can still happen. (happened to me). A simple unique key should prevent this.