Module creation should fail validation when {module} token is present in a componnet name but no position is set on the bay #6388

Closed
opened 2025-12-29 19:40:07 +01:00 by adam · 5 comments
Owner

Originally created by @goebelmeier on GitHub (Apr 21, 2022).

Originally assigned to: @kkthxbye-code on GitHub.

NetBox version

v3.2.1

Python version

3.8

Steps to Reproduce

  1. Create a device with module bays, I had 2 module bays with name ct0 and ct1
  2. Create a module type with interfaces named {module}.eth0
  3. Add the new module to a module bay in the device
  4. Add a second module to the second module bay

Expected Behavior

  1. The placeholder should be replaced by module name resulting in ct0.eth0
  2. The second module should be placed and the interface name should result in ct1.eth0

Observed Behavior

  1. First module creates an interface named .eth0
  2. Second module cannot be created. Error:
<class 'django.db.utils.IntegrityError'>

duplicate key value violates unique constraint "dcim_interface_device_id_name_bffc4ec4_uniq"
DETAIL:  Key (device_id, name)=(4478, .eth0) already exists.


Python version: 3.8.10
NetBox version: 3.2.1
Originally created by @goebelmeier on GitHub (Apr 21, 2022). Originally assigned to: @kkthxbye-code on GitHub. ### NetBox version v3.2.1 ### Python version 3.8 ### Steps to Reproduce 1. Create a device with module bays, I had 2 module bays with name `ct0` and `ct1` 2. Create a module type with interfaces named `{module}.eth0` 3. Add the new module to a module bay in the device 4. Add a second module to the second module bay ### Expected Behavior 1. The placeholder should be replaced by module name resulting in `ct0.eth0` 2. The second module should be placed and the interface name should result in `ct1.eth0` ### Observed Behavior 1. First module creates an interface named `.eth0` 2. Second module cannot be created. Error: ``` <class 'django.db.utils.IntegrityError'> duplicate key value violates unique constraint "dcim_interface_device_id_name_bffc4ec4_uniq" DETAIL: Key (device_id, name)=(4478, .eth0) already exists. Python version: 3.8.10 NetBox version: 3.2.1 ```
adam added the type: bugstatus: accepted labels 2025-12-29 19:40:07 +01:00
adam closed this issue 2025-12-29 19:40:07 +01:00
Author
Owner

@benhur1999 commented on GitHub (Apr 21, 2022):

Did you put any value in the "Position" field when creating the module slots?

I had a same error and it was due to the "Position" field not filled. Maybe Position should be mandatory.

(Edit: I was to open an issue for this, but @goebelmeier had opened one already)

@benhur1999 commented on GitHub (Apr 21, 2022): Did you put any value in the "Position" field when creating the module slots? I had a same error and it was due to the "Position" field not filled. Maybe Position should be mandatory. (Edit: I was to open an issue for this, but @goebelmeier had opened one already)
Author
Owner

@goebelmeier commented on GitHub (Apr 21, 2022):

Did you put any value in the "Position" field when creating the module slots?

I had a same error and it was due to the "Position" field not filled. Maybe Position should be mandatory.

That was the issue, thank you @benhur1999 ! So from my point of view, position should be mandatory too.

@goebelmeier commented on GitHub (Apr 21, 2022): > Did you put any value in the "Position" field when creating the module slots? > > I had a same error and it was due to the "Position" field not filled. Maybe Position should be mandatory. That was the issue, thank you @benhur1999 ! So from my point of view, position should be mandatory too.
Author
Owner

@jeremystretch commented on GitHub (Apr 21, 2022):

The position field is optional because some devices may have unnumbered module bays, and we don't want to force people to make up arbitrary unique identifiers for them. A compromise might be to check for a {module} placeholder when instantiating components, and raise a validation error if the bay into which the module is being installed does not have a position defined.

@jeremystretch commented on GitHub (Apr 21, 2022): The position field is optional because some devices may have unnumbered module bays, and we don't want to force people to make up arbitrary unique identifiers for them. A compromise might be to check for a `{module}` placeholder when instantiating components, and raise a validation error if the bay into which the module is being installed does not have a position defined.
Author
Owner

@benhur1999 commented on GitHub (Apr 22, 2022):

Not making position mandatory makes sense in this case, however the validation should definitely be performed when the {module} is used. Otherwise you may end up with malformed interface names (e.g .eth0) or the django.db.utils.IntegrityError exceptions.

@benhur1999 commented on GitHub (Apr 22, 2022): Not making position mandatory makes sense in this case, however the validation should definitely be performed when the `{module}` is used. Otherwise you may end up with malformed interface names (e.g `.eth0`) or the `django.db.utils.IntegrityError` exceptions.
Author
Owner

@jsenecal commented on GitHub (May 6, 2022):

Faced the same issue today thanks @jeremystretch for the clarification :)

@jsenecal commented on GitHub (May 6, 2022): Faced the same issue today thanks @jeremystretch for the clarification :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6388