netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
http://netboxlabs.com/oss/netbox/
Apache License 2.0
15.98k stars 2.56k forks source link

Error when editing IP #5235

Closed pboatone closed 3 years ago

pboatone commented 4 years ago

Environment

Steps to Reproduce

  1. Go to a device
  2. Add an interface "eth0" 3 Add IP to interface "172.16.3.0/24" 4 Edit IP -> add a NAT IP(inside) like "192.168.3.0/24"
  3. klick "OK"
  4. Following Error when trying to edit IP: 2020-10-12 15_07_23-Window 2020-10-12 15_07_48-Window

Expected Behavior

Expekted is that we want to edit this ip agein.

Observed Behavior

2020-10-12 15_30_38-Window

Originally posted by @pboatone in https://github.com/netbox-community/netbox/issues/5198#issuecomment-707121822

jeremystretch commented 4 years ago

This issue is pending closure as it does not conform to one of the provided templates as required by the contributing guide. If you'd like to request that your issue be re-opened, please first update the content so that it matches the appropriate template (this may require rewriting your issue entirely).

pboatone commented 4 years ago

Updated post on top

DanSheps commented 4 years ago

Could you include the backtrace (should have been emailed hopefully if you configured that)?

szelga commented 3 years ago

not the original poster, but have the same (I reckon) problem.

Environment:

Request Method: GET
Request URL: https://netbox.company.name/ipam/ip-addresses/2384/edit/

Django Version: 3.1
Python Version: 3.7.9
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',
 'timezone_field',
 'circuits',
 'dcim',
 'ipam',
 'extras',
 'secrets',
 'tenancy',
 'users',
 'utilities',
 'virtualization',
 'django_rq',
 '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.RemoteUserMiddleware',
 'utilities.middleware.LoginRequiredMiddleware',
 'utilities.middleware.APIVersionMiddleware',
 'extras.middleware.ObjectChangeMiddleware',
 'django_prometheus.middleware.PrometheusAfterMiddleware']

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.7/site-packages/django/views/generic/base.py", line 73, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/netbox/netbox/utilities/views.py", line 392, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/opt/netbox/netbox/utilities/views.py", line 123, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/django/views/generic/base.py", line 101, in dispatch
    return handler(request, *args, **kwargs)
  File "/opt/netbox/netbox/utilities/views.py", line 398, in get
    form = self.model_form(instance=obj, initial=initial_data)
  File "/opt/netbox/netbox/ipam/forms.py", line 623, in __init__
    initial['nat_rack'] = nat_inside_parent.device.rack.pk

Exception Type: AttributeError at /ipam/ip-addresses/165/edit/
Exception Value: 'NoneType' object has no attribute 'pk'

Netbox 2.9.7 from official docker image. the IP in question has NAT, and was created in a previous Netbox version (2.9.4, probably). other IPs do not trigger this error.

jeremystretch commented 3 years ago

I'm not able to reproduce this behavior on v2.9.7 using the information provided.

bguinet commented 3 years ago

I have the same problem

Python version: 3.6.9 NetBox version: 2.9.8

Steps to Reproduce :

  1. Create a device without rack reference, add an interface to this device
  2. Create an IP address "IP_In" referencing the newly created interface as Assignment
  3. Create an IP address "IP_Out" referencing an the IP address "IP_In" as its NAT inside "By IP"
  4. Edit the newly created IP address "IP_Out"

Expected Behavior : User should be presented with the IP edit form

Observed Behavior : An AttributeError exception is raised:

Traceback (most recent call last):
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/views/generic/base.py", line 73, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/netbox/netbox/utilities/views.py", line 392, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/opt/netbox/netbox/utilities/views.py", line 123, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/views/generic/base.py", line 101, in dispatch
    return handler(request, *args, **kwargs)
  File "/opt/netbox/netbox/utilities/views.py", line 398, in get
    form = self.model_form(instance=obj, initial=initial_data)
  File "/opt/netbox/netbox/ipam/forms.py", line 623, in __init__
    initial['nat_rack'] = nat_inside_parent.device.rack.pk
Exception Type: AttributeError at /ipam/ip-addresses/3547/edit/
Exception Value: 'NoneType' object has no attribute 'pk'

I guess it's related to https://github.com/netbox-community/netbox/issues/5022 and to nat_inside_parent.device.rack wich can be None