-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat: promotion usage limit #13760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
feat: promotion usage limit #13760
Conversation
🦋 Changeset detectedLatest commit: f488408 The changes in this PR will be included in the next version bump. This PR includes changesets to release 74 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 8 Skipped Deployments
|
| id: promotion.id, | ||
| used: newUsedValue, | ||
| }) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Race Condition in Promotion Usage Limit Checks
Race condition in promotion usage limit check: The promotion usage limit is checked by reading the current used value and comparing it with limit, then later updating the database. However, if multiple concurrent requests complete orders with the same promotion code, they could all pass the limit check before any of them updates the database, allowing the promotion to be used more times than the limit allows. For example, if limit is 10 and used is 9, two concurrent requests could both see used=9, pass the check (9+1 <= 10), and both complete successfully, resulting in used=11 which exceeds the limit of 10.
| message: "Automatic promotions cannot have a usage limit", | ||
| path: ["limit"], | ||
| } | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Incomplete Validation Allows Invalid Promotion State
Validation gap allows automatic promotions to have usage limits when updated separately. The refinement only validates fields in the current update request, not the combination with existing promotion state. A promotion with limit: 5 can be updated to is_automatic: true, or vice versa, bypassing the "Automatic promotions cannot have a usage limit" rule. The validation needs to consider both the incoming update data and the existing promotion's current values.
What
Note
Adds promotion usage limits (limit/used) with backend enforcement and tracking, admin create/display UI, type updates, DB migration, and integration tests.
limitandusedtopromotion; expose in admin responses (query-config).computeActions(emitpromotionLimitExceeded) and on usage registration/revert; increment/decrementusedon order completion/revert.is_automaticpromos; prevent loweringlimitbelow currentused.limitfield; schema validation; i18n strings.Usage Limitasused / limit.limit/used; addpromotionLimitExceededaction.limit(nullable int) andused(int, default 0) topromotion; model/snapshot updated.Written by Cursor Bugbot for commit f488408. This will update automatically on new commits. Configure here.