Skip to content

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

@vo42

Description

@vo42

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 17d8f78 that most likely has the same issue (missing Template in the queryset).

I can provide PR if requested.

Metadata

Metadata

Assignees

No one assigned

    Labels

    netboxstatus: needs triageThis issue is awaiting triage by a maintainertype: bugA confirmed report of unexpected behavior in the application

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions