Skip to content

Config Context error in Virtual Machine and Device #5314

@maximebrun

Description

@maximebrun

Environment

  • Python version: 3.7.9 (from docker image python:3.7-alpine)
  • NetBox version: 2.9.8 (migrate from 2.6.9)

Steps to Reproduce

  1. Create a VM.
  2. Add 2 tags to the VM previously created.
  3. Go to Config Context tab of this VM.

Expected Behavior

Display config context information.

Observed Behavior

An Error message :

MultipleObjectsReturned at /virtualization/virtual-machines/399/config-context/

get() returned more than one VirtualMachine -- it returned 2!

2 is the number of tag attached to the VM. A vm with 4 tags will return a error message "-- it returned 4!".

Comment

Problem exist with virtual machine and device.

I'm not very confident it is the way to really fix the issue but perhaps it can help :

Problem seems to be in ConfigContextModelQuerySet class. Adding a distinct in queryset of class VirtualMachineConfigContextView fix the error (I don't use config context so i can't test more).

 class VirtualMachineConfigContextView(ObjectConfigContextView):
-    queryset = VirtualMachine.objects.annotate_config_context_data()
+    queryset = VirtualMachine.objects.distinct().annotate_config_context_data()
     base_template = 'virtualization/virtualmachine.html'

Metadata

Metadata

Assignees

No one assigned

    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