Front port templates: No results when rear_port_id filter is set #11919

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

Originally created by @vo42 on GitHub (Dec 11, 2025).

Originally assigned to: @vo42 on GitHub.

NetBox Edition

NetBox Community

NetBox Version

4.4.8

Python Version

3.12

Steps to Reproduce

  1. Install Netbox with a fresh db
  2. Create a site, device role and a device type. Do NOT create any front port or rear port. No need to create any device.
  3. On the device type (not on a device), click on Add Components, create one rear port and one front port (RearPortTemplate and FrontPortTemplate).
  4. Using the REST API, list the Front Port Templates and check that there is exactly one result, connected to the Rear Port Template with id==1 :
$ curl -s -H "Authorization: Token $TOKEN" 'http://127.0.0.1:8000/api/dcim/front-port-templates/' | jq '.results[] | {id, display, rear_port}'
{
  "id": 1,
  "display": "front",
  "rear_port": {
    "id": 1,
    "url": "http://127.0.0.1:8000/api/dcim/rear-port-templates/1/",
    "display": "rear",
    "name": "rear",
    "description": ""
  }
}
  1. Using the same API route, search for a Front Port Template connected to the Rear Port Template with id = 1 :
$ curl -s -H "Authorization: Token $TOKEN" 'http://127.0.0.1:8000/api/dcim/front-port-templates/?rear_port_id=1'

Expected Behavior

The API should return the same result found in Step 4.

Observed Behavior

{"rear_port_id":["Select a valid choice. 1 is not one of the available choices."]}

I suspect the issue is in class FrontPortTemplateFilterSet in netbox/dcim/filtersets.py: replacing queryset=RearPort.objects.all() by queryset=RearPortTemplate.objects.all() seems to fix the issue.
Note that in the feature branch, a front_port_id filter was added to RearPortTemplateFilterSet by 17d8f78ae3 that most likely has the same issue (missing Template in the queryset).

I can provide PR if requested.

Originally created by @vo42 on GitHub (Dec 11, 2025). Originally assigned to: @vo42 on GitHub. ### NetBox Edition NetBox Community ### NetBox Version 4.4.8 ### Python Version 3.12 ### Steps to Reproduce 1. Install Netbox with a fresh db 2. Create a site, device role and a device type. Do NOT create any front port or rear port. No need to create any device. 3. On the **device _type_** (not on a _device_), click on Add Components, create one rear port and one front port (RearPortTemplate and FrontPortTemplate). 4. Using the REST API, list the Front Port Templates and check that there is exactly one result, connected to the Rear Port Template with id==1 : ``` $ curl -s -H "Authorization: Token $TOKEN" 'http://127.0.0.1:8000/api/dcim/front-port-templates/' | jq '.results[] | {id, display, rear_port}' { "id": 1, "display": "front", "rear_port": { "id": 1, "url": "http://127.0.0.1:8000/api/dcim/rear-port-templates/1/", "display": "rear", "name": "rear", "description": "" } } ``` 5. Using the same API route, search for a Front Port Template connected to the Rear Port Template with id = 1 : ``` $ curl -s -H "Authorization: Token $TOKEN" 'http://127.0.0.1:8000/api/dcim/front-port-templates/?rear_port_id=1' ``` ### Expected Behavior The API should return the same result found in Step 4. ### Observed Behavior ``` {"rear_port_id":["Select a valid choice. 1 is not one of the available choices."]} ``` I suspect the issue is in `class FrontPortTemplateFilterSet` in `netbox/dcim/filtersets.py`: replacing `queryset=RearPort.objects.all()` by `queryset=RearPortTemplate.objects.all()` seems to fix the issue. Note that in the `feature` branch, a front_port_id filter was added to **Rear**PortTemplateFilterSet by 17d8f78ae305396202c45522299ac44adb61373b that most likely has the same issue (missing `Template` in the queryset). I can provide PR if requested.
adam added the type: bugstatus: acceptednetboxseverity: low labels 2025-12-29 21:51:30 +01:00
adam closed this issue 2025-12-29 21:51:30 +01:00
Author
Owner

@jnovinger commented on GitHub (Dec 15, 2025):

Looks like you're correct, @vo42. Assigned to you. Thanks!

@jnovinger commented on GitHub (Dec 15, 2025): Looks like you're correct, @vo42. Assigned to you. Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11919