BOM Validation Improvements - #12780
Conversation
- Optionally skip inclusion of part names - Skip 'piece_count' if default value set
✅ Deploy Preview for inventree-web-pui-preview canceled.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12780 +/- ##
==========================================
+ Coverage 87.09% 87.16% +0.06%
==========================================
Files 1483 1483
Lines 100509 100534 +25
Branches 11527 11602 +75
==========================================
+ Hits 87542 87630 +88
+ Misses 12904 12839 -65
- Partials 63 65 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🔵 Needs a closer look
It changes core BOM validity semantics (including legacy-compatibility behavior) and should get final human verification for correctness and operational impact on existing data.
Pull request overview
This PR fixes BOM validation checksum drift by removing dependency on Part.__str__() (and thus part name/description) from the default BOM / BOM-line hash calculation, while retaining compatibility with legacy checksums already stored in the database.
Changes:
- Update
Part.get_bom_hash()andBomItem.get_item_hash()to optionally include part names for legacy checksum compatibility, while defaulting to a name-independent hash. - Add legacy-fallback logic to
Part.is_bom_valid()andBomItem.is_line_valid()so previously-validated BOMs remain valid after upgrading. - Add a regression test covering legacy checksum recognition, re-validation behavior, and immunity to unrelated Part edits.
File summaries
| File | Description |
|---|---|
| src/backend/InvenTree/part/models.py | Updates BOM and BOM-line hashing + validity checks with legacy fallback support. |
| src/backend/InvenTree/part/test_bom_item.py | Adds regression coverage for legacy compatibility and checksum stability against unrelated Part edits. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Closes #12716
Bug Description
I found that the existing BOM checksum calculation includes the
__str__representation of the assemably and component parts for each BOM item. This means that changing the name for the assembly - or any of the components - will silently invalidate the BOM checksum.This is especially insidious because the BOM validity recalculation is only triggered on updating of a
BomItemobject - not the assembly or component items.This means that BOMs can silently be "invalidated" while their "bom_valid" cached value remains True - as in the linked issue.
Implemented Fix
The new BOM checksum calculation does not include the
__str__values - however when doing a comparison it can fall back to using the old checksum, to ensure that we do not invalidate any BOM checksum values already in the database.