Repository navigation
[bug] Tree fix - #9979
Merged
Merged
[bug] Tree fix#9979
Conversation
- Allow for tree with null items
- Keep tree operations separate (in InvenTreeTree) - Pathstring operations are now in PathStringMixin
- Ensure that this func gets removed in future commit
✅ Deploy Preview for inventree-web-pui-preview canceled.
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #9979 +/- ##
==========================================
+ Coverage 86.76% 86.85% +0.09%
==========================================
Files 1244 1244
Lines 54850 55180 +330
Branches 2106 2106
==========================================
+ Hits 47588 47928 +340
+ Misses 6744 6734 -10
Partials 518 518
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Member
|
Looking interesting @SchrodingersGat; can I review once it is fully done? |
Member
Author
|
@matmair I'll leave this un-merged until you have had a change to properly review. |
- tree_id is somewhat ephemeral
- Test values were wrong, due to bad data in fixtures
- mysql no likey
Contributor
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation and see the Github Action logs for details |
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.
This is a significant bug which was discovered as part of general hardening of tests for the upcoming 1.0.0 release
Background
We make use of the django-mptt library throughout the code, to realize a database-efficient "tree" structure for the following models:
Of these, the
PartCategoryandStockLocationmodels have special consideration (via theInvenTreeTreemodel) which handles node deletion and re-parenting of child nodes.The other models (
Part,StockItemandBuild) inherit directly from theMPTTModelclass, without this mixin shim.However - it turns out that by default,
django-mpttdoes not handle tree rebuilds correctly when a node is deleted from the tree (at least, not in the way that we need it to).So, as per the current code base, if a
StockItem(orPartorBuild) is deleted, and it has child nodes attached, those nodes are effectively orphaned, as they are not correctly re-parented to the upstream node. As these child nodes retain the sametree_idvalue, this creates a corrupted tree, which requires a full rebuild of the model structure (which can be extremely expensive for a large dataset).Changes
This PR removes the direct inheritance from the
MPTTModelclass - instead ensuring that all our "tree" structures inherit from theInvenTreeTreeclass - which correctly handles node deletion, re-parenting, etc.Additionally it adds a significant amount of unit test code to ensure that tree operations are sufficiently covered for all model types, to ensure we do not get a regression here.
To achieve this, the
InvenTreeTreemodel had to be refactored somewhat, and some of the functionality has been split out into another mixin which is relevant only for theStockLocationandPartCategorymodels.There are no migrations or changes to the API.
Backporting
If it can be backported cleanly...
TODO
BuildmodelStockItemmodelPartmodel