Error in Cable creation via POST Api request #5064

Closed
opened 2025-12-29 19:23:42 +01:00 by adam · 3 comments
Owner

Originally created by @coloHsq on GitHub (Jul 13, 2021).

NetBox version

V2.11.9 and previous, at least until 2.11.7

Python version

3.9

Steps to Reproduce

  1. Choose a device, a patch panel or something that has front ports.
  2. Call GET on .../api/dcim/front-ports/?device_id={observed_device}.
  3. Chose a connected front port and disconnect it with a DELETE call on it's cable .../api/dcim/cables/{cable_id}
  4. Create a new cable connected to the old cable peer of the previously chosen front port, by POSTing to .../api/dcim/cables/

Expected Behavior

A new cable should be created without errors

Observed Behavior

The following error is returned

{
  "error": "Cable matching query does not exist.",
  "exception": "DoesNotExist",
  "netbox_version": "2.11.9",
  "python_version": "3.8.10"
}

I assume that this a cache related problem, since, if after it shows up, I launch a 'redis-cli flushall', everything works fine.
Maybe it's something related to cable terminations uniqueness checks done in creation.

P.S. This error says "python_version": "3.8.10" as it comes from the official demo, on my environments it's 3.9.4 but it doesn't seem relevant.

Originally created by @coloHsq on GitHub (Jul 13, 2021). ### NetBox version V2.11.9 and previous, at least until 2.11.7 ### Python version 3.9 ### Steps to Reproduce 1. Choose a device, a patch panel or something that has front ports. 2. Call GET on .../api/dcim/front-ports/?device_id={observed_device}. 3. Chose a connected front port and disconnect it with a DELETE call on it's cable .../api/dcim/cables/{cable_id} 4. Create a new cable connected to the old cable peer of the previously chosen front port, by POSTing to .../api/dcim/cables/ ### Expected Behavior A new cable should be created without errors ### Observed Behavior The following error is returned ``` { "error": "Cable matching query does not exist.", "exception": "DoesNotExist", "netbox_version": "2.11.9", "python_version": "3.8.10" } ``` I assume that this a cache related problem, since, if after it shows up, I launch a 'redis-cli flushall', everything works fine. Maybe it's something related to cable terminations uniqueness checks done in creation. P.S. This error says "python_version": "3.8.10" as it comes from the official demo, on my environments it's 3.9.4 but it doesn't seem relevant.
adam added the type: bug label 2025-12-29 19:23:42 +01:00
adam closed this issue 2025-12-29 19:23:42 +01:00
Author
Owner

@coloHsq commented on GitHub (Jul 13, 2021):

I've done a little bit of debug, it turned out that the described behavior doesn't show up if in step 2 the call is done on Interfaces
So, looking at the related api viewset (under /dcim/api/views.py) it appears that the only difference is '_cable_peer' field in prefetch_related() Interfaces queryset, and adding it to front port viewset seem to solve the problem.
Now, I don't know if it can be a definitive solution or just a workaround, but maybe it can be a start point.

@coloHsq commented on GitHub (Jul 13, 2021): I've done a little bit of debug, it turned out that the described behavior doesn't show up if in step 2 the call is done on Interfaces So, looking at the related api viewset (under /dcim/api/views.py) it appears that the only difference is `'_cable_peer'` field in `prefetch_related()` Interfaces queryset, and adding it to front port viewset seem to solve the problem. Now, I don't know if it can be a definitive solution or just a workaround, but maybe it can be a start point.
Author
Owner

@jeremystretch commented on GitHub (Jul 13, 2021):

I assume that this a cache related problem

Seems like it. You can disable caching by setting CACHE_TIMEOUT = 0 in configuration.py.

I launch a 'redis-cli flushall', everything works fine.

FYI you can use NetBox's management comand manage.py invalidate all to clear the cache without interfering with any queued background tasks (which are also stored in Redis).

Queryset caching support has been removed in the upcoming v3.0 release (see #6639) due to recurring issues such as this one. It is recommended to disable caching for the current release.

@jeremystretch commented on GitHub (Jul 13, 2021): > I assume that this a cache related problem Seems like it. You can disable caching by setting `CACHE_TIMEOUT = 0` in configuration.py. > I launch a 'redis-cli flushall', everything works fine. FYI you can use NetBox's management comand `manage.py invalidate all` to clear the cache without interfering with any queued background tasks (which are also stored in Redis). Queryset caching support has been removed in the upcoming v3.0 release (see #6639) due to recurring issues such as this one. It is recommended to disable caching for the current release.
Author
Owner

@jeremystretch commented on GitHub (Jul 19, 2021):

I'm going to close this out at as the workaround should resolve the issue in the current release, and the queryset caching function will be removed in NetBox v3.0 (see #6639).

@jeremystretch commented on GitHub (Jul 19, 2021): I'm going to close this out at as the workaround should resolve the issue in the current release, and the queryset caching function will be removed in NetBox v3.0 (see #6639).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5064