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:
- Create a product with any attribute;
- Open
eav_attribute_label
and add a new row with the sameattribute_id
andstore_id
values
- Go to Storefront -> Product page
Actual Result: ✖️ Item with the same id already exists.
Expected Result: ✔️ should be notified that duplicate values cannot be created for these fields
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
- #24581 Added unique key on eav_attribute_label table — committed to KaushikChavda/magento2 by deleted user 5 years ago
- #24581 Added unique key on eav_attribute_label table - Fixed pipeline issue. — committed to KaushikChavda/magento2 by deleted user 5 years ago
- #24581 Added unique key on eav_attribute_label table - Fixed Integration tests — committed to KaushikChavda/magento2 by deleted user 5 years ago
- ENGCOM-5977: #24581 Added unique key on eav_attribute_label table #24682 - Merge Pull Request magento/magento2#24682 from KaushikChavda/magento2:issue/24581 - Merged commits: 1. dbf518eb6ccb1ed0... — committed to magento/magento2 by magento-engcom-team 5 years ago
- ENGCOM-5977: #24581 Added unique key on eav_attribute_label table #24682 — committed to magento/magento2 by sidolov 5 years ago
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!
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.