IntegrityError when connecting multiple interfaces to one via a multi-position rear port #3655

Closed
opened 2025-12-29 18:30:24 +01:00 by adam · 1 comment
Owner

Originally created by @jeremystretch on GitHub (May 7, 2020).

Originally assigned to: @jeremystretch on GitHub.

Environment

  • Python version: 3.6.9
  • NetBox version: 2.8.3

Steps to Reproduce

  1. Disable any installed plugins by commenting out the PLUGINS setting in
    configuration.py.
  2. Create or locate three devices (A, B, and C) each with at least one non-connected interface.
  3. Create a device with two front ports mapped to a single rear port.
  4. Connect interface A to the rear port.
  5. Connect interface B to the first front port.
  6. Connect interface C to the second rear port.

Expected Behavior

The third cable should be created.

Observed Behavior

An IntegrityError exception is raised:

Traceback (most recent call last):
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)

The above exception (duplicate key value violates unique constraint "dcim_interface__connected_interface_id_key"
DETAIL:  Key (_connected_interface_id)=(18403) already exists.
) was the direct cause of the following exception:
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/jstretch/netbox/netbox/dcim/views.py", line 2101, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/contrib/auth/mixins.py", line 85, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/views/generic/base.py", line 97, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/jstretch/netbox/netbox/dcim/views.py", line 2129, in post
    obj = form.save()
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/forms/models.py", line 459, in save
    self.instance.save()
  File "/home/jstretch/netbox/netbox/dcim/models/__init__.py", line 2244, in save
    super().save(*args, **kwargs)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/base.py", line 746, in save
    force_update=force_update, update_fields=update_fields)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/base.py", line 795, in save_base
    update_fields=update_fields, raw=raw, using=using,
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 175, in send
    for receiver in self._live_receivers(sender)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 175, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "/home/jstretch/netbox/netbox/dcim/signals.py", line 70, in update_connected_endpoints
    endpoint_a.save()
  File "/home/jstretch/netbox/netbox/dcim/models/device_components.py", line 771, in save
    return super().save(*args, **kwargs)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/base.py", line 746, in save
    force_update=force_update, update_fields=update_fields)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/base.py", line 784, in save_base
    force_update, using, update_fields,
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/base.py", line 865, in _save_table
    forced_update)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/base.py", line 917, in _do_update
    return filtered._update(values) > 0
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/query.py", line 771, in _update
    return query.get_compiler(self.db).execute_sql(CURSOR)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1499, in execute_sql
    cursor = super().execute_sql(result_type)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1151, in execute_sql
    cursor.execute(sql, params)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/debug_toolbar/panels/sql/tracking.py", line 198, in execute
    return self._record(self.cursor.execute, sql, params)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/debug_toolbar/panels/sql/tracking.py", line 133, in _record
    return method(sql, params)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
    return super().execute(sql, params)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/cacheops/transaction.py", line 99, in execute
    result = self._no_monkey.execute(self, sql, params)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)

Exception Type: IntegrityError at /dcim/front-ports/486/connect/interface/
Exception Value: duplicate key value violates unique constraint "dcim_interface__connected_interface_id_key"
DETAIL:  Key (_connected_interface_id)=(18403) already exists.
Originally created by @jeremystretch on GitHub (May 7, 2020). Originally assigned to: @jeremystretch on GitHub. ### Environment * Python version: 3.6.9 * NetBox version: 2.8.3 ### Steps to Reproduce 1. Disable any installed plugins by commenting out the `PLUGINS` setting in `configuration.py`. 2. Create or locate three devices (A, B, and C) each with at least one non-connected interface. 3. Create a device with two front ports mapped to a single rear port. 4. Connect interface A to the rear port. 5. Connect interface B to the first front port. 6. Connect interface C to the second rear port. ### Expected Behavior The third cable should be created. ### Observed Behavior An IntegrityError exception is raised: ``` Traceback (most recent call last): File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute return self.cursor.execute(sql, params) The above exception (duplicate key value violates unique constraint "dcim_interface__connected_interface_id_key" DETAIL: Key (_connected_interface_id)=(18403) already exists. ) was the direct cause of the following exception: File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/views/generic/base.py", line 71, in view return self.dispatch(request, *args, **kwargs) File "/home/jstretch/netbox/netbox/dcim/views.py", line 2101, in dispatch return super().dispatch(request, *args, **kwargs) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/contrib/auth/mixins.py", line 85, in dispatch return super().dispatch(request, *args, **kwargs) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/views/generic/base.py", line 97, in dispatch return handler(request, *args, **kwargs) File "/home/jstretch/netbox/netbox/dcim/views.py", line 2129, in post obj = form.save() File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/forms/models.py", line 459, in save self.instance.save() File "/home/jstretch/netbox/netbox/dcim/models/__init__.py", line 2244, in save super().save(*args, **kwargs) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/base.py", line 746, in save force_update=force_update, update_fields=update_fields) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/base.py", line 795, in save_base update_fields=update_fields, raw=raw, using=using, File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 175, in send for receiver in self._live_receivers(sender) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 175, in <listcomp> for receiver in self._live_receivers(sender) File "/home/jstretch/netbox/netbox/dcim/signals.py", line 70, in update_connected_endpoints endpoint_a.save() File "/home/jstretch/netbox/netbox/dcim/models/device_components.py", line 771, in save return super().save(*args, **kwargs) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/base.py", line 746, in save force_update=force_update, update_fields=update_fields) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/base.py", line 784, in save_base force_update, using, update_fields, File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/base.py", line 865, in _save_table forced_update) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/base.py", line 917, in _do_update return filtered._update(values) > 0 File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/query.py", line 771, in _update return query.get_compiler(self.db).execute_sql(CURSOR) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1499, in execute_sql cursor = super().execute_sql(result_type) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1151, in execute_sql cursor.execute(sql, params) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/debug_toolbar/panels/sql/tracking.py", line 198, in execute return self._record(self.cursor.execute, sql, params) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/debug_toolbar/panels/sql/tracking.py", line 133, in _record return method(sql, params) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute return super().execute(sql, params) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/cacheops/transaction.py", line 99, in execute result = self._no_monkey.execute(self, sql, params) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute return self._execute_with_wrappers(sql, params, many=False, executor=self._execute) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers return executor(sql, params, many, context) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute return self.cursor.execute(sql, params) File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/utils.py", line 90, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/home/jstretch/.virtualenvs/netbox/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute return self.cursor.execute(sql, params) Exception Type: IntegrityError at /dcim/front-ports/486/connect/interface/ Exception Value: duplicate key value violates unique constraint "dcim_interface__connected_interface_id_key" DETAIL: Key (_connected_interface_id)=(18403) already exists. ```
adam added the type: bugstatus: accepted labels 2025-12-29 18:30:24 +01:00
adam closed this issue 2025-12-29 18:30:24 +01:00
Author
Owner

@jeremystretch commented on GitHub (May 7, 2020):

The root issue here is that NetBox permits the connection of an interface (or console port or console server port) to a rear port with multiple positions. When cables are connected, NetBox attempts to automatically resolve any completed end-to-end paths. But conceptually, there is no way that interface A can have end-to-end connections to both interfaces B and C simultaneously.

This problem is closely related to #4519, though that deals specifically with circuit terminations and how they should be treated when calculating end-to-end paths.

@jeremystretch commented on GitHub (May 7, 2020): The root issue here is that NetBox permits the connection of an interface (or console port or console server port) to a rear port with multiple positions. When cables are connected, NetBox attempts to automatically resolve any completed end-to-end paths. But conceptually, there is no way that interface A can have end-to-end connections to both interfaces B and C simultaneously. This problem is closely related to #4519, though that deals specifically with circuit terminations and how they should be treated when calculating end-to-end paths.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3655