mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-11 21:10:29 +01:00
MPTT issues with using nested modules on pre v4.1 data #10205
Closed
opened 2025-12-29 21:28:17 +01:00 by adam
·
10 comments
No Branch/Tag Specified
main
update-changelog-comments-docs
feature-removal-issue-type
20911-dropdown
20239-plugin-menu-classes-mutable-state
21097-graphql-id-lookups
feature
fix_module_substitution
20923-dcim-templates
20044-elevation-stuck-lightmode
feature-ip-prefix-link
v4.5-beta1-release
20068-import-moduletype-attrs
20766-fix-german-translation-code-literals
20378-del-script
7604-filter-modifiers-v3
circuit-swap
12318-case-insensitive-uniqueness
20637-improve-device-q-filter
20660-script-load
19724-graphql
20614-update-ruff
14884-script
02496-max-page
19720-macaddress-interface-generic-relation
19408-circuit-terminations-export-templates
20203-openapi-check
fix-19669-api-image-download
7604-filter-modifiers
19275-fixes-interface-bulk-edit
fix-17794-get_field_value_return_list
11507-show-aggregate-and-rir-on-api
9583-add_column_specific_search_field_to_tables
v4.5.0
v4.4.10
v4.4.9
v4.5.0-beta1
v4.4.8
v4.4.7
v4.4.6
v4.4.5
v4.4.4
v4.4.3
v4.4.2
v4.4.1
v4.4.0
v4.3.7
v4.4.0-beta1
v4.3.6
v4.3.5
v4.3.4
v4.3.3
v4.3.2
v4.3.1
v4.3.0
v4.2.9
v4.3.0-beta2
v4.2.8
v4.3.0-beta1
v4.2.7
v4.2.6
v4.2.5
v4.2.4
v4.2.3
v4.2.2
v4.2.1
v4.2.0
v4.1.11
v4.1.10
v4.1.9
v4.1.8
v4.2-beta1
v4.1.7
v4.1.6
v4.1.5
v4.1.4
v4.1.3
v4.1.2
v4.1.1
v4.1.0
v4.0.11
v4.0.10
v4.0.9
v4.1-beta1
v4.0.8
v4.0.7
v4.0.6
v4.0.5
v4.0.3
v4.0.2
v4.0.1
v4.0.0
v3.7.8
v3.7.7
v4.0-beta2
v3.7.6
v3.7.5
v4.0-beta1
v3.7.4
v3.7.3
v3.7.2
v3.7.1
v3.7.0
v3.6.9
v3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-r1
v1.0.3
1.0.0
Labels
Clear labels
beta
breaking change
complexity: high
complexity: low
complexity: medium
needs milestone
netbox
pending closure
plugin candidate
pull-request
severity: high
severity: low
severity: medium
status: accepted
status: backlog
status: blocked
status: duplicate
status: needs owner
status: needs triage
status: revisions needed
status: under review
topic: GraphQL
topic: Internationalization
topic: OpenAPI
topic: UI/UX
topic: cabling
topic: event rules
topic: htmx navigation
topic: industrialization
topic: migrations
topic: plugins
topic: scripts
topic: templating
topic: testing
type: bug
type: deprecation
type: documentation
type: feature
type: housekeeping
type: translation
Mirrored from GitHub Pull Request
Milestone
No items
No Milestone
Projects
Clear projects
No project
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: starred/netbox#10205
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sleepinggenius2 on GitHub (Sep 9, 2024).
Originally assigned to: @arthanson on GitHub.
Deployment Type
Self-hosted
NetBox Version
v4.1.0
Python Version
3.12
Steps to Reproduce
a. Edit an existing module bay and set the parent to an existing module; OR
b. Add a new module bay with the parent set to an existing module
This has been verified on local systems that have been upgraded to v4.1, but you can also see an example of this happening on the demo site if you add a new module bay "Subslot 0/0" to module "Slot 0" on device "ncsu-coreswitch1". I understand that the demo site cannot be relied on and the example is purely for reference using data included in the standard database refresh.
Expected Behavior
The module bay appears in the list with the correct depth under the module bay for the parent module.
Observed Behavior
When the parent is changed on an existing module bay, the error "A node may not be made a child of any of its descendants." is presented. When a new module bay is added, the new module bay has the correct depth, but does not appear in the correct location in the module bay list.
A new module bay being added to a parent module in a new module bay appears to exhibit the expected behavior.
This looks like classic symptoms of MPTT being out of sync. When RackGroups were made nestable back in v2.8, the following migration was included:
https://github.com/netbox-community/netbox/blob/v2.8.0/netbox/dcim/migrations/0102_nested_rackgroups_rebuild.py. I do not see a similar migration accompanying https://github.com/netbox-community/netbox/blob/v4.1.0/netbox/dcim/migrations/0190_nested_modules.py.
@arthanson commented on GitHub (Sep 9, 2024):
@sleepinggenius2 can you please re-check the repro steps and add further - I used 4.0 with a device that had existing module-bays, then upgraded it to 4.1 and tried step 2.b and it seemed to work fine.
@sleepinggenius2 commented on GitHub (Sep 10, 2024):
This was done locally on a system that was upgraded from 3.7.8 -> 4.0.11 -> 4.1.0.
This is the parent database row from 3.7.8 and 4.0.11:
This is the parent database row after the 4.1.0 upgrade:
In fact, every row in the dcim_modulebay table has the following additional fields after then migration:
After adding the child module bay in the UI, I have this new row in the database:
And this is the record for the parent:
Coincidentally, every row (except the new one) in the dcim_modulebay table now has the following values, presumably because they have the same tree_id value:
Here are the exact steps that I just followed to re-verify:
gunzip -c db_dump.sql.gz | docker compose exec -T postgres sh -c 'psql -U $POSTGRES_USER $POSTGRES_DB'echo 'SELECT * FROM dcim_modulebay WHERE id = 10475\x\g\x' | docker compose exec -T postgres sh -c 'psql -U $POSTGRES_USER $POSTGRES_DB'git clone https://github.com/netbox-community/netbox.gitcd netboxgit fetchgit checkout v4.0.11./upgrade.shcd -echo 'SELECT * FROM dcim_modulebay WHERE id = 10475\x\g\x' | docker compose exec -T postgres sh -c 'psql -U $POSTGRES_USER $POSTGRES_DB'cd -git checkout v4.1.0./upgrade.shcd -echo 'SELECT * FROM dcim_modulebay WHERE id = 10475\x\g\x' | docker compose exec -T postgres sh -c 'psql -U $POSTGRES_USER $POSTGRES_DB'cd -venv/bin/python3 netbox/manage.py runservercd -echo 'SELECT * FROM dcim_modulebay WHERE id = 10475\x\g\x' | docker compose exec -T postgres sh -c 'psql -U $POSTGRES_USER $POSTGRES_DB'echo 'SELECT * FROM dcim_modulebay WHERE id = 60803\x\g\x' | docker compose exec -T postgres sh -c 'psql -U $POSTGRES_USER $POSTGRES_DB'@DanSheps commented on GitHub (Sep 11, 2024):
I also cannot recreate this issue using the original steps (the steps above are just building a docker instance then installing one module bay, which is not helpful)
@arthanson commented on GitHub (Sep 11, 2024):
@sleepinggenius2 we are still not able to reproduce this and the docker steps are not helpful, just include the steps in NetBox that are needed. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.
@sleepinggenius2 commented on GitHub (Sep 12, 2024):
Ok, let's try this:
/dcim/devices/96/module-bays/Slot 0toSlot 13are present and modules are populated inSlot 0andSlot 1Slot 0in the database (SELECT * FROM dcim_modulebay WHERE id = 1) and observetree_id=0, lft=0, right=0, should betree_id=<unique value>, lft=1, right=2Slot 1in the database (SELECT * FROM dcim_modulebay WHERE id = 2) and observetree_id=0, lft=0, right=0, should betree_id=<unique value>, lft=1, right=2/dcim/devices/96/module-bays/Slot 0throughSlot 13are present and modules are populated inSlot 0andSlot 1+ Add Module Baysor+ Add Components > Module BaysModulefield, selectSlot 0: EX9200-32XS (1)Namefield, enterSubslot 0/0CreateSubslot 0/0has the correct depth, but is at the top of the list and not nested underSlot 0, as seen in the screenshot belowSlot 0in the database (SELECT * FROM dcim_modulebay WHERE id = 1) and observetree_id=0, lft=2, right=2, should betree_id=<unique value>, lft=1, right=4Slot 1in the database (SELECT * FROM dcim_modulebay WHERE id = 2) and observetree_id=0, lft=2, right=2, should be unchangedSubslot 0/0in the database (SELECT * FROM dcim_modulebay WHERE id = 29) and observetree_id=0, lft=0, right=1, should betree_id=<unique value, same as Slot 0>, lft=2, right=3It looks like there are actually two issues here. First, is that the default value for
lftandrghthave been set to0instead of1and2respectively, like was done in https://github.com/netbox-community/netbox/blob/v2.8.0/netbox/dcim/migrations/0101_nested_rackgroups.py or https://github.com/netbox-community/netbox/blob/v2.8.0/netbox/tenancy/migrations/0007_nested_tenantgroups.py. Second, is the missing rebuild migration, like was done in https://github.com/netbox-community/netbox/blob/v2.8.0/netbox/dcim/migrations/0102_nested_rackgroups_rebuild.py or https://github.com/netbox-community/netbox/blob/v2.8.0/netbox/tenancy/migrations/0008_nested_tenantgroups_rebuild.py. I can confirm that changing those values innetbox/dcim/migrations/0190_nested_modules.py(lft: default 0 -> 1,rght: default 0 -> 2) and adding the code below tonetbox/dcim/migrations/0191_nested_modules_rebuild.pybefore running the 4.1.0 migration fixes this issue.@DanSheps commented on GitHub (Sep 12, 2024):
Unfortunately we still cannot reproduce any error with your steps. You are describing a cause but not giving us the actual problem. Could you please provide a way for us to replicate this issue on a fresh database?
@sleepinggenius2 commented on GitHub (Sep 12, 2024):
Edit: I saw that NetBox 4.1.1 was released while I was writing this and have confirmed that the issue is still present in that release as well.
The problem is that the MPTT structure in the database is not correct, which also causes incorrect rendering in the UI. Both RackGroups and Tenants were migrated to MPTT in NetBox 2.8.0 and used different migration steps than was done for ModuleBays in NetBox 4.1.0. I thought using the demo dataset would be sufficient for the initial database population, but I have included steps below for creating all the necessary objects through the UI from a clean database. I used a brand new database and a brand new clone of the git repo for the steps below, so I don't know what else to do, if you are still not able to see the same thing I am.
git checkout v4.0.11; ./upgrade.sh)Organization > Sites > AddName = Test, Slug = testCreateDevices > Device Roles > AddName = Test, Slug = testCreateDevices > Manufacturers > AddName = Test, Slug = testCreateDevices > Device Types > AddManufacturer = Test, Model = Test, Slug = testCreateDevices > Module Types > AddManufacturer = Test, Model = TestCreateDevices > Devices > AddName = Test, Device role = Test, Device type = Test, Site = TestCreate+ Add Components > Module BaysName = Slot [0-5]CreateSlot 0, clickInstall moduleModule type = TestCreateSlot 1, clickInstall moduleModule type = TestCreategit checkout v4.1.0; ./upgrade.sh)Devices, then select theTestdeviceModule Baystab to verify everything still looks correct+ Add Components > Module Baysor+ Add Module BaysModule = Slot 0: Test (1), Name = Subslot 0/0CreateSlot 0should havelft = 1, rght = 4,Subslot 0/0should havelft = 2, rght = 3, and those values in the other module bays should have been unchanged.@arthanson commented on GitHub (Sep 19, 2024):
@sleepinggenius2 thank you for the great reproduction steps, I can reproduce it now with the steps.
@arthanson commented on GitHub (Sep 19, 2024):
@sleepinggenius2 can you please try PR #17553 to see If that fixes your issue?
@sleepinggenius2 commented on GitHub (Sep 20, 2024):
I tested against the 4.1.1 database after the steps above and adding the new migration when doing the upgrade from 4.0.11 to 4.1.1 and both resulted in a correct database and UI representation. This seems like an optimal solution for both users that are newly upgrading and fixing the state for anyone that has already upgraded, so a win-win in my book. Thanks!