Exception while creating a device #9900

Closed
opened 2025-12-29 21:24:09 +01:00 by adam · 4 comments
Owner

Originally created by @dteknet on GitHub (Jun 25, 2024).

Originally assigned to: @jeremystretch on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.0.5

Python Version

3.10

Steps to Reproduce

  1. Prerequisites:
    • a site and a rack on that site
    • some random device type
    • some random device role
    • open developer tools in the browser, network tab
  2. Proceed with the nav menu to the Devices section and click on "+" to create a new device
  3. Fill the device name, select the device type, select the site, select the rack
  4. Click on the "x" icon after the rack element clearing the field
    image

Observe the network tab of devtools for failed GET request.

Expected Behavior

No exception is raised.

Observed Behavior

image

Internal Server Error: /api/dcim/racks/{{rack}}/elevation/

ValueError at /api/dcim/racks/{{rack}}/elevation/
Field 'id' expected a number but got '{{rack}}'.

Request Method: GET
Request URL: https://netbox.local/api/dcim/racks/%7B%7Brack%7D%7D/elevation/?brief=true&face=front&limit=100
Django Version: 5.0.6
Python Executable: /opt/netbox/venv/bin/python3
Python Version: 3.10.12
Python Path: ['/opt/netbox/netbox', '/opt/netbox', '/opt/netbox/venv/bin', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/opt/netbox/venv/lib/python3.10/site-packages']
Server time: Tue, 25 Jun 2024 16:11:46 +0300
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'django.forms',
 'corsheaders',
 '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.10/site-packages/django/db/models/fields/__init__.py", line 2117, in get_prep_value
    return int(value)

The above exception (invalid literal for int() with base 10: '{{rack}}') was the direct cause of the following exception:
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/opt/netbox/venv/lib/python3.10/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.10/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper
    return view_func(request, *args, **kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/viewsets.py", line 124, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/netbox/netbox/netbox/api/viewsets/__init__.py", line 135, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/opt/netbox/netbox/dcim/api/views.py", line 184, in elevation
    rack = get_object_or_404(self.queryset, pk=pk)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/shortcuts.py", line 86, in get_object_or_404
    return queryset.get(*args, **kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/query.py", line 635, in get
    clone = self._chain() if self.query.combinator else self.filter(*args, **kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1476, in filter
    return self._filter_or_exclude(False, args, kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1494, in _filter_or_exclude
    clone._filter_or_exclude_inplace(negate, args, kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1501, in _filter_or_exclude_inplace
    self._query.add_q(Q(*args, **kwargs))
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1613, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1645, in _add_q
    child_clause, needed_inner = self.build_filter(
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1559, in build_filter
    condition = self.build_lookup(lookups, col, value)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1389, in build_lookup
    lookup = lookup_class(lhs, rhs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/lookups.py", line 30, in __init__
    self.rhs = self.get_prep_lookup()
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/lookups.py", line 364, in get_prep_lookup
    return super().get_prep_lookup()
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/lookups.py", line 88, in get_prep_lookup
    return self.lhs.output_field.get_prep_value(self.rhs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/fields/__init__.py", line 2119, in get_prep_value
    raise e.__class__(

Exception Type: ValueError at /api/dcim/racks/{{rack}}/elevation/
Exception Value: Field 'id' expected a number but got '{{rack}}'.
Raised during: dcim.api.views.RackViewSet
Request information:
USER: admin

GET:
brief = 'true'
face = 'front'
limit = '100'

POST: No POST data

FILES: No FILES data
Originally created by @dteknet on GitHub (Jun 25, 2024). Originally assigned to: @jeremystretch on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.0.5 ### Python Version 3.10 ### Steps to Reproduce 0. Prerequisites: - a site and a rack on that site - some random device type - some random device role - open developer tools in the browser, network tab 1. Proceed with the nav menu to the Devices section and click on "+" to create a new device 2. Fill the device name, select the device type, select the site, select the rack 3. Click on the "x" icon after the rack element clearing the field ![image](https://github.com/netbox-community/netbox/assets/65331309/fa491405-7b18-4b17-b860-b93e7e9ecf7d) Observe the network tab of devtools for failed GET request. ### Expected Behavior No exception is raised. ### Observed Behavior ![image](https://github.com/netbox-community/netbox/assets/65331309/a1ee8954-f2c8-492f-91c7-fa269a4e86c6) ``` Internal Server Error: /api/dcim/racks/{{rack}}/elevation/ ValueError at /api/dcim/racks/{{rack}}/elevation/ Field 'id' expected a number but got '{{rack}}'. Request Method: GET Request URL: https://netbox.local/api/dcim/racks/%7B%7Brack%7D%7D/elevation/?brief=true&face=front&limit=100 Django Version: 5.0.6 Python Executable: /opt/netbox/venv/bin/python3 Python Version: 3.10.12 Python Path: ['/opt/netbox/netbox', '/opt/netbox', '/opt/netbox/venv/bin', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/opt/netbox/venv/lib/python3.10/site-packages'] Server time: Tue, 25 Jun 2024 16:11:46 +0300 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.humanize', 'django.forms', 'corsheaders', '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.10/site-packages/django/db/models/fields/__init__.py", line 2117, in get_prep_value return int(value) The above exception (invalid literal for int() with base 10: '{{rack}}') was the direct cause of the following exception: File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) File "/opt/netbox/venv/lib/python3.10/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.10/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper return view_func(request, *args, **kwargs) File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/viewsets.py", line 124, in view return self.dispatch(request, *args, **kwargs) File "/opt/netbox/netbox/netbox/api/viewsets/__init__.py", line 135, in dispatch return super().dispatch(request, *args, **kwargs) File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch response = self.handle_exception(exc) File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception self.raise_uncaught_exception(exc) File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception raise exc File "/opt/netbox/venv/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch response = handler(request, *args, **kwargs) File "/opt/netbox/netbox/dcim/api/views.py", line 184, in elevation rack = get_object_or_404(self.queryset, pk=pk) File "/opt/netbox/venv/lib/python3.10/site-packages/django/shortcuts.py", line 86, in get_object_or_404 return queryset.get(*args, **kwargs) File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/query.py", line 635, in get clone = self._chain() if self.query.combinator else self.filter(*args, **kwargs) File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1476, in filter return self._filter_or_exclude(False, args, kwargs) File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1494, in _filter_or_exclude clone._filter_or_exclude_inplace(negate, args, kwargs) File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1501, in _filter_or_exclude_inplace self._query.add_q(Q(*args, **kwargs)) File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1613, in add_q clause, _ = self._add_q(q_object, self.used_aliases) File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1645, in _add_q child_clause, needed_inner = self.build_filter( File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1559, in build_filter condition = self.build_lookup(lookups, col, value) File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1389, in build_lookup lookup = lookup_class(lhs, rhs) File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/lookups.py", line 30, in __init__ self.rhs = self.get_prep_lookup() File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/lookups.py", line 364, in get_prep_lookup return super().get_prep_lookup() File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/lookups.py", line 88, in get_prep_lookup return self.lhs.output_field.get_prep_value(self.rhs) File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/fields/__init__.py", line 2119, in get_prep_value raise e.__class__( Exception Type: ValueError at /api/dcim/racks/{{rack}}/elevation/ Exception Value: Field 'id' expected a number but got '{{rack}}'. Raised during: dcim.api.views.RackViewSet Request information: USER: admin GET: brief = 'true' face = 'front' limit = '100' POST: No POST data FILES: No FILES data ```
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:24:09 +01:00
adam closed this issue 2025-12-29 21:24:09 +01:00
Author
Owner

@arthanson commented on GitHub (Jun 25, 2024):

Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v4.0.5. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.

@arthanson commented on GitHub (Jun 25, 2024): Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v4.0.5. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.
Author
Owner

@dteknet commented on GitHub (Jun 26, 2024):

Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v4.0.5. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.

Hi Arthur,
I forgot to mention that you need to look for it in the browser dev tools, network tab. As an administrator, I'm receiving an e-mail each time someone triggers the issue. There's no visible exception in the browser other than a failed GET request which you can find in the network tab. I was able to reproduce the same error on the demo site (demo.netbox.dev).

@dteknet commented on GitHub (Jun 26, 2024): > Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v4.0.5. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data. Hi Arthur, I forgot to mention that you need to look for it in the browser dev tools, network tab. As an administrator, I'm receiving an e-mail each time someone triggers the issue. There's no visible exception in the browser other than a failed GET request which you can find in the network tab. I was able to reproduce the same error on the demo site (demo.netbox.dev).
Author
Owner

@Kani999 commented on GitHub (Jun 26, 2024):

  • Error Internal Server Error: /api/dcim/racks/{{rack}}/elevation/ also happens, when you edit a Device with assigned Rack. When you click on changing a Site (then a Rack is changed to None) I will receive an e-mail from NetBox with message:
Internal Server Error: /api/dcim/racks/{{rack}}/elevation/

ValueError at /api/dcim/racks/{{rack}}/elevation/
Field 'id' expected a number but got '{{rack}}'.
  • I suppose this error happens during API call to racks while selecting objects in the UI
  • Using NetBox v4.0.6
@Kani999 commented on GitHub (Jun 26, 2024): - Error `Internal Server Error: /api/dcim/racks/{{rack}}/elevation/` also happens, when you edit a `Device` with assigned `Rack`. When you click on changing a Site (then a Rack is changed to None) I will receive an e-mail from NetBox with message: ``` Internal Server Error: /api/dcim/racks/{{rack}}/elevation/ ValueError at /api/dcim/racks/{{rack}}/elevation/ Field 'id' expected a number but got '{{rack}}'. ``` - I suppose this error happens during API call to racks while selecting objects in the UI - Using NetBox v4.0.6
Author
Owner

@SYNLINQ commented on GitHub (Jul 1, 2024):

Hello,

can confirm, just got the same exact issue.

@SYNLINQ commented on GitHub (Jul 1, 2024): Hello, can confirm, just got the same exact issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9900