bug(plugin-ecommerce): duplicate variant check ignores drafts
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- nodejs, sqlite, typescript
Research direction
Read packages/plugin-ecommerce/src/collections/variants/createVariantsCollection/hooks/validateOptions.ts, especially the findByID lookup and variant exclusion filter. Run the reproduction's pnpm test:int in variant-duplicate-check-ignores-drafts/ to see the failure. Done means publishing variant B succeeds after variant A's options change is saved as a draft; an open linked pull request is already addressing this issue.
Written by the indexing model from the issue text.
Description
Describe the Bug
The ecommerce plugin validates that no two variants of a product use the same options combination. The check in validateOptions loads the product's variants join with findByID without draft: true, so it compares against the other variants' published options. Variants have drafts, and changes saved as a draft don't touch the published values.
So when a variant's options are corrected in a draft, its old combination still counts as taken. Creating variants, fixing their options as drafts, and then publishing them one by one fails with "This variant combo is already in use by another variant", although no variant uses that combination any more. The variant stays unpublished until the other variant is published first.
The check should read the latest drafts. Note that with draft: true the join's id: { not_equals: data.id } filter no longer excludes the variant being validated (at least on SQLite), so that variant then has to be excluded from the results by ID instead. Otherwise it is compared with itself and every publish is rejected.
This affects both v3 and v4: the same code ships in 4.0.0-beta.4 and is on main.
Link to the code that reproduces this issue
Reproduction Steps
- Clone this repo and open the
variant-duplicate-check-ignores-drafts/directory pnpm installpnpm test:int: the test publishes variant A with the option "Small", changes A to "Large" in a draft, creates variant B as a draft with "Small", and publishes B.
Publishing B is rejected:
× compares against the latest draft of the other variants' options
AssertionError: promise rejected "ValidationError: The following field is invalid: Variant options" instead of resolving
Which area(s) are affected?
plugin: ecommerce
Environment Info
Relevant Packages:
payload: 3.92.0
@payloadcms/plugin-ecommerce: 3.92.0
@payloadcms/db-sqlite: 3.92.0
Node: 22.23.3, pnpm: 11.5.1, darwin arm64
- Dominant language
- TypeScript
- Stars
- 45.6k
- Forks
- 4.4k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 280
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from payloadcms/payload
-
Form Builder Plugin: an internal link in an email message stops all of the form's emailsPossibly taken @DoctorGuidance claimed this 1 day ago. OpenBug plugin: form-builder status: needs-triage v3
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
payloadcms/payload#19253 ·
Maintainers usually reply within 1 day
-
Required Lexical field accepts two empty paragraphsPossibly taken @lazerg claimed this 3 days ago. OpenBug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
payloadcms/payload#19222 ·
Maintainers usually reply within 1 day
-
area: ui Bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
payloadcms/payload#19198 ·
Maintainers usually reply within 1 day
-
Grid view: show the file placeholder when a thumbnail image fails to loadPossibly taken @lazerg claimed this 4 days ago. OpenBug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
payloadcms/payload#19181 ·
Maintainers usually reply within 1 day
-
WhereBuilder throws "Cannot read properties of undefined (reading 'value')" when the list URL filters on a field that is not filterablePossibly taken A pull request linked to this issue is open or already merged. OpenBug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
payloadcms/payload#19002 · 1 comment ·
Maintainers usually reply within 1 day
All issues in payloadcms/payload
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
oxidecomputer/skepsis#102 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
voidzero-dev/void#677 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
kunchenguid/gh-axi#247 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
lidge-jun/opencodex#8101 · 2 comments ·
Maintainers usually reply within 1 day