[bug] Fix concurrency issues for allocation - #12478
Merged
SchrodingersGat merged 4 commits intoJul 28, 2026
Merged
Conversation
✅ Deploy Preview for inventree-web-pui-preview canceled.
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #12478 +/- ##
==========================================
+ Coverage 86.84% 86.85% +0.01%
==========================================
Files 1443 1442 -1
Lines 95693 95790 +97
Branches 11121 11094 -27
==========================================
+ Hits 83104 83203 +99
+ Misses 12525 12522 -3
- Partials 64 65 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
SchrodingersGat
marked this pull request as draft
July 27, 2026 22:25
SchrodingersGat
marked this pull request as ready for review
July 28, 2026 01:38
Lowkey-wizard
added a commit
to EQUA-AI/InvenTree
that referenced
this pull request
Aug 7, 2026
Upstream inventree#12361/inventree#12478 route all build-allocation validation through the new StockItem.bulk_allocation_count() and persist via bulk_create, which bypasses BuildItem.clean(). Add the job-kit domain as the fourth accumulator so builds cannot consume maintenance-reserved stock, and teach can_delete() to refuse cleanly on job-kit rows (PROTECT FK) instead of raising ProtectedError. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Issue reported by @nullbenny
Issue Description
unallocated_quantity()is read without a lock, while writes lock only the order row (not the shared StockItem) and insert via bulk_create, so concurrent requests against the same StockItem can all pass validation and all commit — confirmed on POST /api/build/{id}/allocate/, where two concurrent requests each allocating a full 5-unit stock item both returned 201, leaving 10 allocated against 5 (~90% reproduction rate across repeated runs). The same gap exists in the sales-order, serial-based sales-order, and transfer-order allocation paths, and since unallocated_quantity() sums across all three subsystems, over-allocation can occur both within and across them.