Skip to content

ValueError exception when migrating to v2.11.5 with one or more VRFs defined #6544

@jeremystretch

Description

@jeremystretch

NetBox version

v2.11.5

Python version

3.7

Steps to Reproduce

  1. Start with NetBox v2.11.4 or earlier
  2. Create a VRF
  3. Create one or more prefixes within that VRF
  4. Upgrade to NetBox v2.11.5

Expected Behavior

The upgrade should complete successfully.

Observed Behavior

A ValueError exception is raised due to a bug in the way VRFs are retrieved in the migration:

ValueError: Cannot query "VRF object (1)": Must be "VRF" instance.

It seems that Django does not like using the "faked" VRF instance returned by apps.get_model() for filtering. It's being cast as a string by filter() rather than its numeric ID beign evaluated.

VRF = apps.get_model('ipam', 'VRF')
...
    # Iterate through all VRFs, rebuilding each
    for vrf in VRF.objects.all():
        rebuild_prefixes(vrf)

Altering the migration to reference the ID directly resolves the issue:

        rebuild_prefixes(vrf.pk)
$ ./manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, circuits, contenttypes, dcim, extras, ipam, secrets, sessions, taggit, tenancy, users, virtualization
Running migrations:
  Applying ipam.0048_prefix_populate_depth_children...
Updating 3157 prefixes...
 OK

Metadata

Metadata

Assignees

Labels

status: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions