Skip to content

fix: change slug column collation to utf8mb4_bin to fix accent-sensitive uniqueness#391

Open
ahuininga-orisha wants to merge 4 commits into
developfrom
fix/230529-slug-collation-utf8mb4-bin
Open

fix: change slug column collation to utf8mb4_bin to fix accent-sensitive uniqueness#391
ahuininga-orisha wants to merge 4 commits into
developfrom
fix/230529-slug-collation-utf8mb4-bin

Conversation

@ahuininga-orisha

@ahuininga-orisha ahuininga-orisha commented May 27, 2026

Copy link
Copy Markdown
Collaborator

When the PathSlugStrategy is active, filter option labels are transliterated to ASCII slugs and stored in the database. The unique index on the slug column used an accent-insensitive collation, meaning the database treated e, é, and è as identical. Two filter values from different languages that happen to produce the same ASCII slug would silently collide, causing the wrong filter to be applied to the wrong products.

The fix changes the slug column to a binary collation (utf8mb4_bin), making the unique index accent- and case-sensitive. This collation is compatible with both MySQL 8 and MariaDB. Since slugs are always lowercased ASCII after transliteration, binary comparison is safe. A second patch cleans up duplicate legacy indexes left behind by an earlier migration.

Run bin/magento setup:upgrade after installing.

Changes

File What changed
Setup/Patch/Schema/CleanupLegacyIndexesTweakwiseAttributeSlugTable.php Drops the legacy ATTRIBUTE and STORE_SLUG indexes that duplicated the canonical Magento-named indexes left behind by ChangePrimaryKeyTweakwiseAttributeSlugTable
Setup/Patch/Schema/SetSlugColumnCollationTweakwiseAttributeSlugTable.php Alters the slug column to CHARACTER SET utf8mb4 COLLATE utf8mb4_bin so accent-distinct slugs are treated as unique by the database index

How to test

Scenario 1 — Legacy indexes are removed


  1. On a store with an existing tweakwise_attribute_slug table, run bin/magento setup:upgrade.
  2. Run SHOW INDEX FROM tweakwise_attribute_slug; in MySQL.
  3. Verify that indexes named ATTRIBUTE and STORE_SLUG no longer exist.
  4. Verify that TWEAKWISE_ATTRIBUTE_SLUG_ATTRIBUTE_STORE_ID and TWEAKWISE_ATTRIBUTE_SLUG_STORE_ID_SLUG are present.

Scenario 2 — Slug column uses utf8mb4_bin collation


  1. Run SHOW CREATE TABLE tweakwise_attribute_slug;.
  2. Verify the slug column shows CHARACTER SET utf8mb4 COLLATE utf8mb4_bin.

Scenario 3 — Accent-distinct slugs no longer collide


  1. Manually insert two rows with store_id = 1, slugs e and ë respectively into tweakwise_attribute_slug.
  2. Verify both inserts succeed without a duplicate key error.
  3. Delete the test rows.

Scenario 4 — PathSlugStrategy filter URLs still resolve correctly


  1. Navigate to a category page with active PathSlugStrategy.
  2. Select a filter option containing a diacritic character (e.g. Röd, crème).
  3. Verify the URL contains the correctly transliterated slug (e.g. rod, creme).
  4. Verify the correct filter is applied and products are filtered as expected.
  5. Reload the page via the slug URL directly and verify the filter remains selected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant