-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MPTT issues with using nested modules on pre v4.1 data #17419
Comments
@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. |
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:
|
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) |
@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. |
Ok, let's try this:
It looks like there are actually two issues here. First, is that the default value for from django.db import migrations
def rebuild_mptt(apps, schema_editor):
ModuleBay = apps.get_model('dcim', 'ModuleBay')
for i, modulebay in enumerate(ModuleBay.objects.all(), start=1):
ModuleBay.objects.filter(pk=modulebay.pk).update(tree_id=i)
class Migration(migrations.Migration):
dependencies = [
('dcim', '0190_nested_modules'),
]
operations = [
migrations.RunPython(
code=rebuild_mptt,
reverse_code=migrations.RunPython.noop
),
] |
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 thank you for the great reproduction steps, I can reproduce it now with the steps. |
@sleepinggenius2 can you please try PR #17553 to see If that fixes your issue? |
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! |
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.
The text was updated successfully, but these errors were encountered: