fix(plugin): use app_name instead of plugin_path when deregistering models#11536
Open
nino-tan-smartee wants to merge 6 commits intoinventree:masterfrom
Open
fix(plugin): use app_name instead of plugin_path when deregistering models#11536nino-tan-smartee wants to merge 6 commits intoinventree:masterfrom
nino-tan-smartee wants to merge 6 commits intoinventree:masterfrom
Conversation
…odels _deactivate_mixin uses plugin_path (the full dotted module path) as the key into Django's apps.all_models when removing plugin models during reload. However, Django registers models under the app_label (the short app_name), not the full plugin_path. For plugins with nested module paths (e.g. "myplugin.myplugin"), plugin_path != app_name. Since apps.all_models is a defaultdict, looking up plugin_path silently creates an empty OrderedDict, then .pop(model) raises KeyError because the model was never in that dict — it was registered under app_name. This causes recurring KeyError crashes every plugin reload cycle (~1 minute) for any external plugin with a nested package structure. The fix: - Use app_name (already computed at line 98) instead of plugin_path - Add default None to .pop() for defensive safety - Consistent with line 123 which already correctly uses app_name
…eyerror fix(plugin): use app_name instead of plugin_path when deregistering models
✅ Deploy Preview for inventree-web-pui-preview canceled.
|
Member
|
@nino-tan-smartee thank you for the PR; please add a unit test that ensures the fixed issues does not appear again |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #11536 +/- ##
==========================================
- Coverage 88.08% 88.08% -0.01%
==========================================
Files 1296 1296
Lines 59182 59182
Branches 1934 1934
==========================================
- Hits 52133 52132 -1
- Misses 6569 6570 +1
Partials 480 480
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Ensures _deactivate_mixin uses app_name (last path component) instead of the full plugin_path when looking up models in apps.all_models, preventing KeyError for external plugins with nested module structures.
…eyerror test(plugin): add unit test for nested plugin path model deregistration
Author
@matmair I added the unit test |
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.
Summary
_deactivate_mixinusesplugin_path(full dotted module path) as the key intoapps.all_modelswhen removing plugin models during reloadapp_label(shortapp_name), not the fullplugin_pathmyplugin.myplugin),plugin_path != app_nameapps.all_modelsis adefaultdict, looking upplugin_pathsilently creates an emptyOrderedDict, then.pop(model)raisesKeyErrorKeyErrorcrashes every plugin reload cycle (~1 minute) for any external plugin with a nested package structureFix
app_name(already computed at line 98) instead ofplugin_pathon line 118Noneto.pop()for defensive safetyapp_nameReproduction
purchase_quotation/purchase_quotation/)KeyError: '<model_name>'in error reports every plugin reload cycleTest plan