AttributeError at /dcim/devices/ #18489
Replies: 1 comment
-
Tracing the issueThe line that is crashing is here.
Here is the source code for def model_class(self):
"Returns the Python model class for this type of content."
try:
return apps.get_model(self.app_label, self.model)
except LookupError:
return None So, it's indeed a failed lookup that got silenced.. ConclusionBasically, you have CustomField that reference a model that doesn't exist anymore. It might have been renamed, moved to another module (typically, AFAIK, Netbox does the migrations for the core models, but there are multiple ways it could have gone wrong. Basically, the custom module should be in charge of migrating it. Fixing itYou can test it manually from the console I guess. I don't know how efficient this will be. Otherwise, a small script will give you the answer:
It should look like this (Not tested at the moment): import extras
all_custom_fields = extras.models.CustomField.objects.all()
bogus_fields = []
for cf in all_custom_fields:
cls = cf.related_object_type.model_class()
if cls is None:
bogus_fields.append(cf)
for cf in bogus_fields:
print(f"{cf.name} ({cf.id}) is invalid: model {cf.related_object_type.natural_key()} doesn't exist anymore") This should give you the list of CustomFields that are causing issues. The easiest to fix your issue might be to delete the fields (and re-create them if needed). Otherwise, you might just find the new name and do the change from the console. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I need help...with
This happened after I installed a plugin and installed an update for netbox.
Maybe someone has an idea and could help me?
Thank you very much!
I get this error message
-> Devices -> Devices
-> Organization -> Location
`
Environment:
Request Method: GET
Request URL: https://***/dcim/devices/
Django Version: 5.1.5
Python Version: 3.12.7
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django.forms',
'corsheaders',
'debug_toolbar',
'django_filters',
'django_htmx',
'django_tables2',
'django_prometheus',
'strawberry_django',
'mptt',
'rest_framework',
'social_django',
'taggit',
'timezone_field',
'core',
'account',
'circuits',
'dcim',
'ipam',
'extras',
'tenancy',
'users',
'utilities',
'virtualization',
'vpn',
'wireless',
'django_rq',
'drf_spectacular',
'drf_spectacular_sidecar']
Installed Middleware:
['strawberry_django.middlewares.debug_toolbar.DebugToolbarMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'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',
'django_htmx.middleware.HtmxMiddleware',
'netbox.middleware.RemoteUserMiddleware',
'netbox.middleware.CoreMiddleware',
'netbox.middleware.MaintenanceModeMiddleware']
Traceback (most recent call last):
File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/netbox/venv/lib/python3.12/site-packages/django/views/generic/base.py", line 104, in view
return self.dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/netbox/netbox/netbox/views/generic/base.py", line 77, in dispatch
return super().dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/netbox/netbox/utilities/views.py", line 125, in dispatch
return super().dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/netbox/netbox/utilities/views.py", line 39, in dispatch
return super().dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/netbox/venv/lib/python3.12/site-packages/django/views/generic/base.py", line 143, in dispatch
return handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/netbox/netbox/netbox/views/generic/bulk_views.py", line 190, in get
'filter_form': self.filterset_form(request.GET) if self.filterset_form else None,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/netbox/netbox/netbox/forms/base.py", line 173, in init
super().init(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/netbox/netbox/netbox/forms/mixins.py", line 31, in init
self._append_customfield_fields()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/netbox/netbox/netbox/forms/mixins.py", line 57, in _append_customfield_fields
self.fields[field_name] = self._get_form_field(customfield)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/netbox/netbox/netbox/forms/base.py", line 188, in _get_form_field
return customfield.to_form_field(set_initial=False, enforce_required=False, enforce_visibility=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/netbox/netbox/extras/models/customfields.py", line 529, in to_form_field
'queryset': model.objects.all(),
^^^^^^^^^^^^^
Exception Type: AttributeError at /dcim/devices/
Exception Value: 'NoneType' object has no attribute 'objects'
`
Beta Was this translation helpful? Give feedback.
All reactions