Attempting to add a Virtual Machine from the UI fails with a ValueError #7085

Closed
opened 2025-12-29 20:19:01 +01:00 by adam · 4 comments
Owner

Originally created by @AmandaCameron on GitHub (Oct 6, 2022).

NetBox version

v3.3.4

Python version

3.10

Steps to Reproduce

  1. Attempt to add a VirtualMachine
  2. Get a ValueError from the interface ipv4 checking

Expected Behavior

The VirtualMAchine should be created

Observed Behavior

ValueError happens, stacktrace:

Oct 06 12:05:31 miranda gunicorn[8155]: Internal Server Error: /virtualization/virtual-machines/add/
Oct 06 12:05:31 miranda gunicorn[8155]: Traceback (most recent call last):
Oct 06 12:05:31 miranda gunicorn[8155]:   File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
Oct 06 12:05:31 miranda gunicorn[8155]:     response = get_response(request)
Oct 06 12:05:31 miranda gunicorn[8155]:   File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
Oct 06 12:05:31 miranda gunicorn[8155]:     response = wrapped_callback(request, *callback_args, **callback_kwargs)
Oct 06 12:05:31 miranda gunicorn[8155]:   File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/views/generic/base.py", line 103, in view
Oct 06 12:05:31 miranda gunicorn[8155]:     return self.dispatch(request, *args, **kwargs)
Oct 06 12:05:31 miranda gunicorn[8155]:   File "/nix/store/4dv2b7babkjg9q4iq2v26iww12md41ab-netbox-3.3.4/opt/netbox/netbox/netbox/views/generic/object_views.py", line 302, in dispatch
Oct 06 12:05:31 miranda gunicorn[8155]:     return super().dispatch(request, *args, **kwargs)
Oct 06 12:05:31 miranda gunicorn[8155]:   File "/nix/store/4dv2b7babkjg9q4iq2v26iww12md41ab-netbox-3.3.4/opt/netbox/netbox/utilities/views.py", line 90, in dispatch
Oct 06 12:05:31 miranda gunicorn[8155]:     return super().dispatch(request, *args, **kwargs)
Oct 06 12:05:31 miranda gunicorn[8155]:   File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/views/generic/base.py", line 142, in dispatch
Oct 06 12:05:31 miranda gunicorn[8155]:     return handler(request, *args, **kwargs)
Oct 06 12:05:31 miranda gunicorn[8155]:   File "/nix/store/4dv2b7babkjg9q4iq2v26iww12md41ab-netbox-3.3.4/opt/netbox/netbox/netbox/views/generic/object_views.py", line 384, in post
Oct 06 12:05:31 miranda gunicorn[8155]:     if form.is_valid():
Oct 06 12:05:31 miranda gunicorn[8155]:   File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/forms/forms.py", line 205, in is_valid
Oct 06 12:05:31 miranda gunicorn[8155]:     return self.is_bound and not self.errors
Oct 06 12:05:31 miranda gunicorn[8155]:   File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/forms/forms.py", line 200, in errors
Oct 06 12:05:31 miranda gunicorn[8155]:     self.full_clean()
Oct 06 12:05:31 miranda gunicorn[8155]:   File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/forms/forms.py", line 439, in full_clean
Oct 06 12:05:31 miranda gunicorn[8155]:     self._post_clean()
Oct 06 12:05:31 miranda gunicorn[8155]:   File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/forms/models.py", line 492, in _post_clean
Oct 06 12:05:31 miranda gunicorn[8155]:     self.instance.full_clean(exclude=exclude, validate_unique=False)
Oct 06 12:05:31 miranda gunicorn[8155]:   File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/db/models/base.py", line 1471, in full_clean
Oct 06 12:05:31 miranda gunicorn[8155]:     self.clean()
Oct 06 12:05:31 miranda gunicorn[8155]:   File "/nix/store/4dv2b7babkjg9q4iq2v26iww12md41ab-netbox-3.3.4/opt/netbox/netbox/virtualization/models.py", line 370, in clean
Oct 06 12:05:31 miranda gunicorn[8155]:     interfaces = self.interfaces.all()
Oct 06 12:05:31 miranda gunicorn[8155]:   File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/db/models/manager.py", line 164, in all
Oct 06 12:05:31 miranda gunicorn[8155]:     return self.get_queryset()
Oct 06 12:05:31 miranda gunicorn[8155]:   File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/db/models/fields/related_descriptors.py", line 698, in get_queryset
Oct 06 12:05:31 miranda gunicorn[8155]:     raise ValueError(
Oct 06 12:05:31 miranda gunicorn[8155]: ValueError: 'VirtualMachine' instance needs to have a primary key value before this relationship can be used.
Originally created by @AmandaCameron on GitHub (Oct 6, 2022). ### NetBox version v3.3.4 ### Python version 3.10 ### Steps to Reproduce 1. Attempt to add a VirtualMachine 2. Get a ValueError from the interface ipv4 checking ### Expected Behavior The VirtualMAchine should be created ### Observed Behavior ValueError happens, stacktrace: ``` Oct 06 12:05:31 miranda gunicorn[8155]: Internal Server Error: /virtualization/virtual-machines/add/ Oct 06 12:05:31 miranda gunicorn[8155]: Traceback (most recent call last): Oct 06 12:05:31 miranda gunicorn[8155]: File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner Oct 06 12:05:31 miranda gunicorn[8155]: response = get_response(request) Oct 06 12:05:31 miranda gunicorn[8155]: File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response Oct 06 12:05:31 miranda gunicorn[8155]: response = wrapped_callback(request, *callback_args, **callback_kwargs) Oct 06 12:05:31 miranda gunicorn[8155]: File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/views/generic/base.py", line 103, in view Oct 06 12:05:31 miranda gunicorn[8155]: return self.dispatch(request, *args, **kwargs) Oct 06 12:05:31 miranda gunicorn[8155]: File "/nix/store/4dv2b7babkjg9q4iq2v26iww12md41ab-netbox-3.3.4/opt/netbox/netbox/netbox/views/generic/object_views.py", line 302, in dispatch Oct 06 12:05:31 miranda gunicorn[8155]: return super().dispatch(request, *args, **kwargs) Oct 06 12:05:31 miranda gunicorn[8155]: File "/nix/store/4dv2b7babkjg9q4iq2v26iww12md41ab-netbox-3.3.4/opt/netbox/netbox/utilities/views.py", line 90, in dispatch Oct 06 12:05:31 miranda gunicorn[8155]: return super().dispatch(request, *args, **kwargs) Oct 06 12:05:31 miranda gunicorn[8155]: File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/views/generic/base.py", line 142, in dispatch Oct 06 12:05:31 miranda gunicorn[8155]: return handler(request, *args, **kwargs) Oct 06 12:05:31 miranda gunicorn[8155]: File "/nix/store/4dv2b7babkjg9q4iq2v26iww12md41ab-netbox-3.3.4/opt/netbox/netbox/netbox/views/generic/object_views.py", line 384, in post Oct 06 12:05:31 miranda gunicorn[8155]: if form.is_valid(): Oct 06 12:05:31 miranda gunicorn[8155]: File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/forms/forms.py", line 205, in is_valid Oct 06 12:05:31 miranda gunicorn[8155]: return self.is_bound and not self.errors Oct 06 12:05:31 miranda gunicorn[8155]: File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/forms/forms.py", line 200, in errors Oct 06 12:05:31 miranda gunicorn[8155]: self.full_clean() Oct 06 12:05:31 miranda gunicorn[8155]: File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/forms/forms.py", line 439, in full_clean Oct 06 12:05:31 miranda gunicorn[8155]: self._post_clean() Oct 06 12:05:31 miranda gunicorn[8155]: File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/forms/models.py", line 492, in _post_clean Oct 06 12:05:31 miranda gunicorn[8155]: self.instance.full_clean(exclude=exclude, validate_unique=False) Oct 06 12:05:31 miranda gunicorn[8155]: File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/db/models/base.py", line 1471, in full_clean Oct 06 12:05:31 miranda gunicorn[8155]: self.clean() Oct 06 12:05:31 miranda gunicorn[8155]: File "/nix/store/4dv2b7babkjg9q4iq2v26iww12md41ab-netbox-3.3.4/opt/netbox/netbox/virtualization/models.py", line 370, in clean Oct 06 12:05:31 miranda gunicorn[8155]: interfaces = self.interfaces.all() Oct 06 12:05:31 miranda gunicorn[8155]: File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/db/models/manager.py", line 164, in all Oct 06 12:05:31 miranda gunicorn[8155]: return self.get_queryset() Oct 06 12:05:31 miranda gunicorn[8155]: File "/nix/store/a5jkkcc8v5s0wz9qv6kb3928hd2bls76-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/db/models/fields/related_descriptors.py", line 698, in get_queryset Oct 06 12:05:31 miranda gunicorn[8155]: raise ValueError( Oct 06 12:05:31 miranda gunicorn[8155]: ValueError: 'VirtualMachine' instance needs to have a primary key value before this relationship can be used. ```
adam added the type: bug label 2025-12-29 20:19:01 +01:00
adam closed this issue 2025-12-29 20:19:01 +01:00
Author
Owner

@jeremystretch commented on GitHub (Oct 7, 2022):

Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.

@jeremystretch commented on GitHub (Oct 7, 2022): Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.
Author
Owner

@AmandaCameron commented on GitHub (Oct 8, 2022):

I'm 99% sure that the problem is that the version of Django that NixOS uses is causing a full_clean on the VirtualMachine model, and this line is triggering a query referencing an un-inserted VirtualMachine object, so the VMInterface query doesn't have a VirtualMachine primary key to use.

NixOS Django is 4.1.1

@AmandaCameron commented on GitHub (Oct 8, 2022): I'm 99% sure that the problem is that the version of Django that NixOS uses is causing a full_clean on the VirtualMachine model, and [this line](https://github.com/netbox-community/netbox/blob/develop/netbox/virtualization/models.py#L368) is triggering a query referencing an un-inserted VirtualMachine object, so the VMInterface query doesn't have a VirtualMachine primary key to use. NixOS Django is 4.1.1
Author
Owner

@kkthxbye-code commented on GitHub (Oct 8, 2022):

I'm gonna close this out. I would think the right place to raise the issue is here: https://github.com/NixOS/nixpkgs

Please note that we do not support the nix package and that we do not support running dependency versions that differ from the ones found in the requirements.txt file.

If you manage to replicate this on a supported netbox install method, please let me know and I'll reopen the ticket.

@kkthxbye-code commented on GitHub (Oct 8, 2022): I'm gonna close this out. I would think the right place to raise the issue is here: https://github.com/NixOS/nixpkgs Please note that we do not support the nix package and that we do not support running dependency versions that differ from the ones found in the requirements.txt file. If you manage to replicate this on a supported netbox install method, please let me know and I'll reopen the ticket.
Author
Owner

@centromere commented on GitHub (Oct 27, 2022):

@AmandaCameron This PR may help. The changes haven't yet landed in a release though.

@centromere commented on GitHub (Oct 27, 2022): @AmandaCameron [This PR](https://github.com/netbox-community/netbox/pull/10341) may help. The changes haven't yet landed in a release though.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7085