Skip to content

BOM Validation Improvements - #12780

Open
SchrodingersGat wants to merge 5 commits into
inventree:masterfrom
SchrodingersGat:bom-validate
Open

BOM Validation Improvements#12780
SchrodingersGat wants to merge 5 commits into
inventree:masterfrom
SchrodingersGat:bom-validate

Conversation

@SchrodingersGat

@SchrodingersGat SchrodingersGat commented Sep 3, 2026

Copy link
Copy Markdown
Member

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 BomItem object - 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.

- Optionally skip inclusion of part names
- Skip 'piece_count' if default value set
@SchrodingersGat SchrodingersGat added this to the 1.6.0 milestone Sep 3, 2026
@SchrodingersGat SchrodingersGat added bug Identifies a bug which needs to be addressed backport Apply this label to a PR to enable auto-backport action area/BOM related to BOM/assembly logic and possible engine improvements backport-to-1.5.x labels Sep 3, 2026
@netlify

netlify Bot commented Sep 3, 2026

Copy link
Copy Markdown

Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit 6af40ec
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6a9a3e5fc3a91c0008d0d9eb

@SchrodingersGat SchrodingersGat mentioned this pull request Sep 3, 2026
1 task
@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.16%. Comparing base (ff732d0) to head (6af40ec).

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     
Flag Coverage Δ
backend 91.16% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Backend Apps 92.43% <100.00%> (+<0.01%) ⬆️
Backend General 94.68% <ø> (ø)
Frontend 79.84% <ø> (+0.15%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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() and BomItem.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() and BomItem.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.

Comment thread src/backend/InvenTree/part/models.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/BOM related to BOM/assembly logic and possible engine improvements backport Apply this label to a PR to enable auto-backport action backport-to-1.5.x bug Identifies a bug which needs to be addressed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bom validation fails

3 participants