Server error when adding a duplicate secret #3738

Closed
opened 2025-12-29 18:30:51 +01:00 by adam · 2 comments
Owner

Originally created by @nmereddi on GitHub (May 31, 2020).

Environment

  • Python version: 3.7
  • NetBox version: 2.8.4

Steps to Reproduce

  1. Create a secret, say S1 for a device D1, for a secret role R1
  2. Repeat step 1. Netbox throws a server error

Expected Behavior

Throw a validation error on the form rather a server error to be consistent with other features.

Observed Behavior

There was a problem with your request. Please contact an administrator.

<class 'django.db.utils.IntegrityError'>

duplicate key value violates unique constraint "secrets_secret_device_id_role_id_name_f8acc218_uniq"
DETAIL: Key (device_id, role_id, name)=(1, 1, S1) already exists.

Originally created by @nmereddi on GitHub (May 31, 2020). ### Environment * Python version: 3.7 * NetBox version: 2.8.4 ### Steps to Reproduce 1. Create a secret, say S1 for a device D1, for a secret role R1 2. Repeat step 1. Netbox throws a server error ### Expected Behavior Throw a validation error on the form rather a server error to be consistent with other features. ### Observed Behavior There was a problem with your request. Please contact an administrator. <class 'django.db.utils.IntegrityError'> duplicate key value violates unique constraint "secrets_secret_device_id_role_id_name_f8acc218_uniq" DETAIL: Key (device_id, role_id, name)=(1, 1, S1) already exists.
adam added the type: bugstatus: accepted labels 2025-12-29 18:30:51 +01:00
adam closed this issue 2025-12-29 18:30:51 +01:00
Author
Owner

@itdependsnetworks commented on GitHub (May 31, 2020):

I'm just a passerby, so my thoughts do not carry too much weight. However, I believe you are conflating form validation (via schema) and database integrity. Forms can relatively easily ensure that you meet a validation check such as email address, character length etc with javascript. For this, a SQL query would need to be made, which is actually a lot more complex (not just a little).

IMHO, this would add little value but incur a lot of technical debt and error prone.

@itdependsnetworks commented on GitHub (May 31, 2020): I'm just a passerby, so my thoughts do not carry too much weight. However, I believe you are conflating form validation (via schema) and database integrity. Forms can relatively easily ensure that you meet a validation check such as email address, character length etc with javascript. For this, a SQL query would need to be made, which is actually a lot more complex (not just a little). IMHO, this would add little value but incur a lot of technical debt and error prone.
Author
Owner

@itdependsnetworks commented on GitHub (Jun 1, 2020):

I stand corrected :)

@itdependsnetworks commented on GitHub (Jun 1, 2020): I stand corrected :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3738