Fix: duplicate attribute slugs#381
Open
ahuininga-orisha wants to merge 8 commits into
Open
Conversation
added 2 commits
May 12, 2026 14:00
jansentjeu
requested changes
May 15, 2026
| @@ -289,6 +300,7 @@ protected function loadLookupTable(): array | |||
| public function truncateSlugTable(): void | |||
| { | |||
| $this->attributeSlugRepository->truncateSlugTable(); | |||
| $this->lookupTable = null; | |||
Collaborator
There was a problem hiding this comment.
$this->lookupTable = null; or $this->lookupTable = [];?
Collaborator
Author
There was a problem hiding this comment.
getLookupTable() has a if ($this->lookupTable === null) guard (line 267) that triggers a DB reload
Setting it to [] would skip that check and return an empty array on the next call, meaning the in-memory cache would never be reloaded after a truncate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #337 and #363
Summary
FixSlugUniqueIndexOnTweakwiseAttributeSlugTable) that drops the global unique index onslug(introduced inInstallSchema) and replaces it with a composite unique index on(slug, store_id). This is the root cause of theUnique constraint violationerror when saving product attributes in the admin.AttributeSlugRepository::save()now loads any existing row by(attribute, store_id)before the collision loop and sets its primary key on the entity, soresource->save()always issues anUPDATEinstead of a duplicateINSERT.FilterSlugManager(getSlugForFilterItem,saveAttributeSlugForOptionLabel,createFilterSlugByOption) now update$this->lookupTableimmediately after a successful save. Previously, a second call for the same attribute within the same request would miss the in-memory table, fall through tosave()again, and trigger another unnecessary DB write.FilterSlugManager::truncateSlugTable()now resets$this->lookupTable = nullso the nextgetLookupTable()call reloads from DB rather than serving the pre-truncate in-memory state.createFilterSlugByOption()now callsgetLookupTable()before writing to$this->lookupTableto ensure the property is always initialised before use.How to test
Scenario 1 — Admin attribute save no longer throws a unique constraint violation
tweakwise/layered/url_strategyis set toPathSlugStrategyand slugs have already been generated (visit a category page or runtweakwise:regenerate:filter-url-slugs).Catalog > Attributes > Product, open any existing attribute and click Save Attribute.Could not save the page: Unique constraint violation founderror appears.Scenario 2 — Slug collision resolution still works across stores
tweakwise:regenerate:filter-url-slugs.tweakwise_attribute_slugtable contains separate rows per(slug, store_id)combination.Scenario 3 — In-memory cache is updated after a new slug is created
tweakwise_attribute_slugtable and clear the Magento cache.getSlugForFilterItem()for each filter.getSlugForFilterItem()and verify thatsave()is called exactly once per attribute per store, not twice, even when multiple filters are rendered in the same request.Scenario 4 — Truncating the slug table reloads correctly
FilterSlugManager::truncateSlugTable()(via the CLI command or directly in a test).