Skip to content

UI filter forms should filter by numeric ID rather than by slug #5894

@jeremystretch

Description

@jeremystretch

Proposed Changes

Currently, when filtering a list of objects within the NetBox web UI, many of the provided search fields apply a query filter based on the selected object's slug. For example, filtering for all devices in a site with the slug raleigh4 would apply the query parameter ?site=raleigh-4.

This issue proposes changing all such fields to reference the related object by its numeric ID instead. For example, the above query would become ?site_id=123, where 123 is the site's primary key.

To be clear, this does not change the behavior of the actual filters, and will not have any effect on external consumers of the REST API. It merely changes which of the existing filters NetBox's own UI uses.

Justification

Although more human-friendly, filtering by a related object's slug field requires a SQL JOIN when making the database query to pull in the related object:

SELECT DISTINCT ...
  FROM "dcim_device"
 INNER JOIN "dcim_site"
    ON ("dcim_device"."site_id" = "dcim_site"."id")
 WHERE "dcim_site"."slug" = 'raleigh4'
 ORDER BY "dcim_device"."_name" ASC, "dcim_device"."id" ASC

Filtering by the related object's ID does not require a JOIN, because that value is stored in the filtered object's foreign key field.

Metadata

Metadata

Assignees

Labels

status: acceptedThis issue has been accepted for implementationtype: housekeepingChanges to the application which do not directly impact the end user

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions