Power outlet creation fails - PowerOutlet has no device. #2569

Closed
opened 2025-12-29 18:20:02 +01:00 by adam · 0 comments
Owner

Originally created by @ghost on GitHub (May 1, 2019).

Environment

  • Python version: 3.6.6
  • NetBox version: develop-2.6

Steps to Reproduce

  1. On an existing device, create a new power outlet component via the 'add component' form (dcim/devices/device_id/power-outlets/add/)
  2. click submit

Expected Behavior

Power outlet created

Observed Behavior

Traceback -

<class 'dcim.models.PowerOutlet.device.RelatedObjectDoesNotExist'>

PowerOutlet has no device.

Debug details:

Environment:


Request Method: POST
Request URL: https://netbox.domain.local/dcim/devices/3105/power-outlets/add/

Django Version: 2.2
Python Version: 3.6.6
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'cacheops',
 'corsheaders',
 'debug_toolbar',
 'django_filters',
 'django_tables2',
 'django_prometheus',
 'mptt',
 'rest_framework',
 'taggit',
 'taggit_serializer',
 'timezone_field',
 'circuits',
 'dcim',
 'ipam',
 'extras',
 'secrets',
 'tenancy',
 'users',
 'utilities',
 'virtualization',
 'drf_yasg']
Installed Middleware:
('debug_toolbar.middleware.DebugToolbarMiddleware',
 'django_prometheus.middleware.PrometheusBeforeMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'utilities.middleware.ExceptionHandlingMiddleware',
 'utilities.middleware.LoginRequiredMiddleware',
 'utilities.middleware.APIVersionMiddleware',
 'extras.middleware.ObjectChangeMiddleware',
 'django_prometheus.middleware.PrometheusAfterMiddleware')



Traceback:

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py" in view
  71.             return self.dispatch(request, *args, **kwargs)

File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/mixins.py" in dispatch
  85.         return super().dispatch(request, *args, **kwargs)

File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py" in dispatch
  97.         return handler(request, *args, **kwargs)

File "/opt/netbox/netbox/utilities/views.py" in post
  744.                 component_form = self.model_form(data)

File "/opt/netbox/netbox/dcim/forms.py" in __init__
  2010.             device=self.instance.device

File "/usr/local/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py" in __get__
  189.                 "%s has no %s." % (self.field.model.__name__, self.field.name)

Exception Type: RelatedObjectDoesNotExist at /dcim/devices/3105/power-outlets/add/
Exception Value: PowerOutlet has no device.

If I remove the 'limit power_port choices to the local device' part of dcim/forms.py, this works perfectly well.

If I comment out the below from PowerOutletForm this works as expected - power_port isn't currently part of PowerOutletCreateForm so this doesn't appear to have a lot of impact currently.

Relevant code introduced in 3d5f85c0ca:

        # Limit power_port choices to the local device
        self.fields['power_port'].queryset = PowerPort.objects.filter(
            device=self.instance.device
        )

Originally created by @ghost on GitHub (May 1, 2019). <!-- NOTE: This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.6.6 <!-- Example: 3.5.4 --> * NetBox version: develop-2.6 <!-- Example: 2.5.2 --> <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox (or the current beta release where applicable). Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a wrapper like pynetbox. --> ### Steps to Reproduce 1. On an existing device, create a new power outlet component via the 'add component' form (dcim/devices/*device_id*/power-outlets/add/) 2. click submit <!-- What did you expect to happen? --> ### Expected Behavior Power outlet created <!-- What happened instead? --> ### Observed Behavior Traceback - ``` <class 'dcim.models.PowerOutlet.device.RelatedObjectDoesNotExist'> PowerOutlet has no device. ``` Debug details: ``` Environment: Request Method: POST Request URL: https://netbox.domain.local/dcim/devices/3105/power-outlets/add/ Django Version: 2.2 Python Version: 3.6.6 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.humanize', 'cacheops', 'corsheaders', 'debug_toolbar', 'django_filters', 'django_tables2', 'django_prometheus', 'mptt', 'rest_framework', 'taggit', 'taggit_serializer', 'timezone_field', 'circuits', 'dcim', 'ipam', 'extras', 'secrets', 'tenancy', 'users', 'utilities', 'virtualization', 'drf_yasg'] Installed Middleware: ('debug_toolbar.middleware.DebugToolbarMiddleware', 'django_prometheus.middleware.PrometheusBeforeMiddleware', 'corsheaders.middleware.CorsMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', 'utilities.middleware.ExceptionHandlingMiddleware', 'utilities.middleware.LoginRequiredMiddleware', 'utilities.middleware.APIVersionMiddleware', 'extras.middleware.ObjectChangeMiddleware', 'django_prometheus.middleware.PrometheusAfterMiddleware') Traceback: File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner 34. response = get_response(request) File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response 115. response = self.process_exception_by_middleware(e, request) File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response 113. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py" in view 71. return self.dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/mixins.py" in dispatch 85. return super().dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py" in dispatch 97. return handler(request, *args, **kwargs) File "/opt/netbox/netbox/utilities/views.py" in post 744. component_form = self.model_form(data) File "/opt/netbox/netbox/dcim/forms.py" in __init__ 2010. device=self.instance.device File "/usr/local/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py" in __get__ 189. "%s has no %s." % (self.field.model.__name__, self.field.name) Exception Type: RelatedObjectDoesNotExist at /dcim/devices/3105/power-outlets/add/ Exception Value: PowerOutlet has no device. ``` If I remove the 'limit power_port choices to the local device' part of dcim/forms.py, this works perfectly well. If I comment out the below from PowerOutletForm this works as expected - power_port isn't currently part of PowerOutletCreateForm so this doesn't appear to have a lot of impact currently. Relevant code introduced in 3d5f85c0cab0a0c5f003304b2b005bae13b97f2a: ``` # Limit power_port choices to the local device self.fields['power_port'].queryset = PowerPort.objects.filter( device=self.instance.device ) ```
adam added the type: bugstatus: accepted labels 2025-12-29 18:20:02 +01:00
adam closed this issue 2025-12-29 18:20:02 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2569