Magento2: MIssing unique key on eav_attribute_label table

Created on 13 Sep 2019  路  18Comments  路  Source: magento/magento2

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: :heavy_multiplication_x: Item with the same id already exists.

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

Expected Result: :heavy_check_mark: 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>
FrameworDB Confirmed P2 ready for dev Reported on 2.3.2 Reproduced on 2.4.x S2 Dev.Experience

All 18 comments

Hi @tzyganu. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [x] Summary of the issue
  • [x] Information on your environment
  • [x] Steps to reproduce
  • [x] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@tzyganu do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [x] yes
  • [ ] no

Hi @engcom-Charlie. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

Hello @tzyganu !
Could you add any steps?

@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.

@engcom-Charlie Thank you for verifying the issue.

Unfortunately, not enough information was provided to acknowledge ticket. Please consider adding the following:

  • [ ] Add "Component: " label(s) to this ticket based on verification result. If uncertain, you may follow the best guess

Once all required information is added, please add label "Issue: Confirmed" again.
Thanks!

:white_check_mark: Confirmed by @engcom-Charlie
Thank you for verifying the issue. Based on the provided information internal tickets MC-20164 were created

Issue Available: @engcom-Charlie, _You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself._

Hi @KaushikChavda. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [x] 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


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.

Closing since it was fixed on https://github.com/magento/magento2/pull/24682

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

@magento I am working on this

Hi @alex311982! :wave:
Thank you for collaboration. Only members of Community Contributors Team are allowed to be assigned to the issue. Please use @magento add to contributors team command to join Contributors team.

@magento add to contributors team

Hi @alex311982! :wave:
Thank you for joining. Please accept team invitation :point_right: here :point_left: and add your comment one more time.

@magento I am working on this

@gabrieldagama as we discussed in Slack - this is really terrible issue, it's causing not obvious issues. In my case it was caused by some custom module, and behavior was like was "I just pressed some button and whole website went down", but real issue came from NOT OBVIOUS missing unique key.

We have 2 the same issues for two tables:
https://github.com/magento/magento2/issues/24581 - P2 S2 (as for me this is right priority)
https://github.com/magento/magento2/issues/24718 - P3 S3

Also for them we have open PRs:
https://github.com/magento/magento2/pull/28796 (in "to approval" status since end of July)
https://github.com/magento/magento2/pull/30981 (in review currently, waiting for test results, but I'm ready to approve it)

Would be good to move them forward together

BTW the issue was already fixed in October 2019, but then fix was reverted
https://github.com/magento/magento2/issues/24581#issuecomment-537933794

:white_check_mark: Confirmed by @engcom-Alfa
Thank you for verifying the issue. Based on the provided information internal tickets MC-39328 were created

Issue Available: @engcom-Alfa, _You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself._

Was this page helpful?
0 / 5 - 0 ratings