Skip to content

AttributeSlugRepository unable to save an attribute with a slightly different name #402

Description

@LeonidasJP

Tweakwise-M2: v8.11, v9.0.1
Magento: 2.4.8-p5
DB: MariaDB 11

Having a Product Attribute with Options, slightly renaming an option from - for example - Café to Cafe does not work - resulting in a database constraint violation on the ATTRIBUTE key on the tweakwise_attribute_slug table.

This seems to be failing when an attribute with almost the same name (either with or without accented letters like above) exists for the same storeview

Of the 2749 attribute slugs in tweakwise_attribute_slug, only six have an attribute_code.

While debugging Model/AttributeSlugRepository.php::save(), I noticed the following:

  • Existing attribute in table: attribute=Café, slug=cafe, store_id=0, attribute_code=chair_type
  • Update the Admin Code of the attribute from Café to Cafe and save the Attribute --> error
    • baseSlug = cafe
    • storeId = 0
    • existingSlug found, but with another Attribute value (Resp. Cafe (new) and Café (existing)), so counter +1
    • New slug cafe-1 doesn't exist, so while-loop is exited
    • New slug cafe-1 for attribute Cafe and StoreID 0 is persisted --> Unique Constraint Violation with message SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'Cafe-0' for key 'ATTRIBUTE', query was: INSERT INTO 'tweakwise_attribute_slug' ('attribute', 'slug', 'store_id', 'attribute_code') VALUES ('Cafe', 'cafe-1', 0, 'chair_type')
  • Attribute Update gets reverted...

Looks like MariaDB normalizes characters in keys, where accented letters get replaced to their base accentless variant...

What can be done to fix this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions