fix: sync line.variantId to resolved variant ID to prevent inventory lock collision - #1733
Merged
BHUVANSH855 merged 1 commit intoSep 12, 2026
Conversation
…lock collision Signed-off-by: Dhiraj Maurya <mauryadheeraj226@gmail.com>
🔍 Quality Gate Report✅ All quality gates passed!
|
🤖 AI Code Review🔴 Score: 50/100 | AI review unavailable at this time. Automated AI review — a human maintainer will also review. |
|
@d4-dhiraj is attempting to deploy a commit to the Bhuvansh's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
💡 Suggested reviewers based on relevant file history: @Pcmhacker-hero, @Aditya8369 |
🔴 PR Health Score: 40/100This PR's health score is below the 75/100 threshold for a healthy label.
Improving these signals will help reviewers engage faster and raise your score. 💪 |
|
@d4-dhiraj 🎊 First merged PR in this repo — welcome to the Hiero contributor community! |
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.
Summary
Fixes #1722
reserveStockInTransaction()resolves a variant viaresolveLockVariant()when aline specifies attribute choices (color/size) instead of an explicit
variantId,but
line.variantIditself was never updated to match. This left it atNO_VARIANT_IDeven after the correct variant was resolved.Because both the lock-check
SELECTand the lock-creationINSERTkey offline.variantId, requests for the same physical variant made via explicitvariantIdvs. viacolor/sizewere landing in different lock buckets andnever serializing against each other — allowing concurrent reservations to
oversell the same stock.
Fix
After
resolveLockVariant()resolves a variant,line.variantIdis now syncedto
variant.idwhenever it wasn't already set to a real ID:Using
<= NO_VARIANT_ID(rather than a truthy check) keeps this consistent withhow the rest of the file already treats
NO_VARIANT_ID(seehasVariantChoice()and
lockLine()), regardless of what sentinel value it's actually set to.Both downstream queries already read from
line.variantId, so no other changeswere needed — they now automatically operate on the correct, resolved ID.
Testing
Manually verified locally: sent one reservation request with an explicit
variantIdand one withcolor/sizefor the same variant (stock = 1).Before the fix, both succeeded. After the fix, the second correctly returns
INVENTORY_CONFLICT.No automated test added — happy to add one if a maintainer can point me to the
existing test pattern for this service.