Error when import modules into device that doesn't have a name #11391

Open
opened 2025-12-29 21:44:32 +01:00 by adam · 4 comments
Owner

Originally created by @sol1-matt on GitHub (Jul 17, 2025).

Originally assigned to: @bctiemann on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.3.4

Python Version

3.11

Steps to Reproduce

  1. Create device without a name and module bays named Bay 1 and Bay 2 in positions 1 and 2
{
    "id": 11531,
    "display": "ACME FOBOT Chassis 1 (11531)",
    "name": null,
    "device_type": {
        "id": 731,
        "display": "FOBOT Chassis 1",
        "manufacturer": {
            "id": 234,
            "display": "ACME",
            "name": "ACME",
            "slug": "acme",
        },
        "model": "FOBOT Chassis 1",
        "slug": "fobot-chassis-1",
  1. Create a module Module1234
  2. Import modules
device,module_bay,module_type,status
ACME FOBOT Chassis 1 (11531),"Bay 1",Module1234,planned

An error occurs:

Server Error
The complete exception is provided below: 

<class 'dcim.models.modules.Module.module_bay.RelatedObjectDoesNotExist'>

Module has no module_bay.

Python version: 3.11.2
NetBox version: 4.3.3

Additional steps
4. Edit the device and add a name to the device created in step 1 FOBOT 1
5. Import modules

device,module_bay,module_type,status
FOBOT 1,"Bay 1",Module1234,planned

The Module is added to device from import when the device has a name.

Expected Behavior

Netbox shouldn't throw a Server Error when importing devices without names.

The import should fail with a failure message telling the user you can't import to devices without a name but to use device.id instead.

Workaround
Import to the device.id instead of the device

device.id,module_bay,module_type,status
11531,"Bay 1",Module1234,planned

Observed Behavior

Server Error
The complete exception is provided below: 

<class 'dcim.models.modules.Module.module_bay.RelatedObjectDoesNotExist'>

Module has no module_bay.

Python version: 3.11.2
NetBox version: 4.3.3
Originally created by @sol1-matt on GitHub (Jul 17, 2025). Originally assigned to: @bctiemann on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.3.4 ### Python Version 3.11 ### Steps to Reproduce 1. Create device without a name and module bays named `Bay 1` and `Bay 2` in positions 1 and 2 ``` { "id": 11531, "display": "ACME FOBOT Chassis 1 (11531)", "name": null, "device_type": { "id": 731, "display": "FOBOT Chassis 1", "manufacturer": { "id": 234, "display": "ACME", "name": "ACME", "slug": "acme", }, "model": "FOBOT Chassis 1", "slug": "fobot-chassis-1", ``` 2. Create a module `Module1234` 3. Import modules ``` device,module_bay,module_type,status ACME FOBOT Chassis 1 (11531),"Bay 1",Module1234,planned ``` An error occurs: ``` Server Error The complete exception is provided below: <class 'dcim.models.modules.Module.module_bay.RelatedObjectDoesNotExist'> Module has no module_bay. Python version: 3.11.2 NetBox version: 4.3.3 ``` **Additional steps** 4. Edit the device and add a name to the device created in step 1 `FOBOT 1` 5. Import modules ``` device,module_bay,module_type,status FOBOT 1,"Bay 1",Module1234,planned ``` The Module is added to device from import when the device has a name. ### Expected Behavior Netbox shouldn't throw a Server Error when importing devices without names. The import should fail with a failure message telling the user you can't import to devices without a name but to use `device.id` instead. **Workaround** Import to the device.id instead of the device ``` device.id,module_bay,module_type,status 11531,"Bay 1",Module1234,planned ``` ### Observed Behavior ``` Server Error The complete exception is provided below: <class 'dcim.models.modules.Module.module_bay.RelatedObjectDoesNotExist'> Module has no module_bay. Python version: 3.11.2 NetBox version: 4.3.3 ```
adam added the type: bugstatus: acceptednetboxseverity: low labels 2025-12-29 21:44:32 +01:00
Author
Owner

@sol1-matt commented on GitHub (Jul 17, 2025):

found a working import value

device.id,module_bay,module_type,status
11531,"Bay 1",Module1234,planned
@sol1-matt commented on GitHub (Jul 17, 2025): found a working import value ``` device.id,module_bay,module_type,status 11531,"Bay 1",Module1234,planned ```
Author
Owner

@jnovinger commented on GitHub (Jul 18, 2025):

I missed the "no name" detail at first and was really confused when the first import worked. 🤦

Here is the full stack trace:

  File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/views/generic/base.py", line 105, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/jnovinger/development/netbox-community/netbox/netbox/netbox/views/generic/base.py", line 77, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/Users/jnovinger/development/netbox-community/netbox/netbox/utilities/views.py", line 125, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/Users/jnovinger/development/netbox-community/netbox/netbox/utilities/views.py", line 39, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/views/generic/base.py", line 144, in dispatch
    return handler(request, *args, **kwargs)
  File "/Users/jnovinger/development/netbox-community/netbox/netbox/netbox/views/generic/bulk_views.py", line 523, in post
    new_objects = self.create_and_update_objects(form, request)
  File "/Users/jnovinger/development/netbox-community/netbox/netbox/netbox/views/generic/bulk_views.py", line 470, in create_and_update_objects
    if model_form.is_valid():
  File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/forms/forms.py", line 206, in is_valid
    return self.is_bound and not self.errors
  File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/forms/forms.py", line 201, in errors
    self.full_clean()
  File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/forms/forms.py", line 339, in full_clean
    self._post_clean()
  File "/Users/jnovinger/development/netbox-community/netbox/netbox/netbox/forms/base.py", line 78, in _post_clean
    return super()._post_clean()
  File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/forms/models.py", line 498, in _post_clean
    self.instance.full_clean(exclude=exclude, validate_unique=False)
  File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/db/models/base.py", line 1654, in full_clean
    self.clean()
  File "/Users/jnovinger/development/netbox-community/netbox/netbox/dcim/models/modules.py", line 268, in clean
    if module.pk in modules or module.module_bay.pk in module_bays:
  File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/db/models/fields/related_descriptors.py", line 271, in __get__
    raise self.RelatedObjectDoesNotExist(

Exception Type: RelatedObjectDoesNotExist at /dcim/modules/import/
Exception Value: Module has no module_bay.
@jnovinger commented on GitHub (Jul 18, 2025): I missed the "no name" detail at first and was really confused when the first import worked. 🤦 Here is the full stack trace: ``` File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/views/generic/base.py", line 105, in view return self.dispatch(request, *args, **kwargs) File "/Users/jnovinger/development/netbox-community/netbox/netbox/netbox/views/generic/base.py", line 77, in dispatch return super().dispatch(request, *args, **kwargs) File "/Users/jnovinger/development/netbox-community/netbox/netbox/utilities/views.py", line 125, in dispatch return super().dispatch(request, *args, **kwargs) File "/Users/jnovinger/development/netbox-community/netbox/netbox/utilities/views.py", line 39, in dispatch return super().dispatch(request, *args, **kwargs) File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/views/generic/base.py", line 144, in dispatch return handler(request, *args, **kwargs) File "/Users/jnovinger/development/netbox-community/netbox/netbox/netbox/views/generic/bulk_views.py", line 523, in post new_objects = self.create_and_update_objects(form, request) File "/Users/jnovinger/development/netbox-community/netbox/netbox/netbox/views/generic/bulk_views.py", line 470, in create_and_update_objects if model_form.is_valid(): File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/forms/forms.py", line 206, in is_valid return self.is_bound and not self.errors File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/forms/forms.py", line 201, in errors self.full_clean() File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/forms/forms.py", line 339, in full_clean self._post_clean() File "/Users/jnovinger/development/netbox-community/netbox/netbox/netbox/forms/base.py", line 78, in _post_clean return super()._post_clean() File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/forms/models.py", line 498, in _post_clean self.instance.full_clean(exclude=exclude, validate_unique=False) File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/db/models/base.py", line 1654, in full_clean self.clean() File "/Users/jnovinger/development/netbox-community/netbox/netbox/dcim/models/modules.py", line 268, in clean if module.pk in modules or module.module_bay.pk in module_bays: File "/Users/jnovinger/.virtualenvs/netbox/lib/python3.10/site-packages/django/db/models/fields/related_descriptors.py", line 271, in __get__ raise self.RelatedObjectDoesNotExist( Exception Type: RelatedObjectDoesNotExist at /dcim/modules/import/ Exception Value: Module has no module_bay. ```
Author
Owner

@jnovinger commented on GitHub (Jul 18, 2025):

Thanks for identifying and noting the workarounds, @sol1-matt !

@jnovinger commented on GitHub (Jul 18, 2025): Thanks for identifying and noting the workarounds, @sol1-matt !
Author
Owner

@github-actions[bot] commented on GitHub (Oct 17, 2025):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Oct 17, 2025): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/main/CONTRIBUTING.md).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11391