Ability to filter objects by an associated request ID #7510

Closed
opened 2025-12-29 20:24:30 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Jan 13, 2023).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.4.2

Feature type

New functionality

Proposed functionality

Add new filters to NetBoxModelFilterSet which enable a user to filter for objects based on the ID and action of an associated change record. For example, suppose you want to find all sites that were created as the result of a specific request. This proposal would enable you to filter send a request such as:

GET /dcim/sites/?objectchange_request_id=e39c84bc-f169-4d5f-bc1c-94487a1b18b5

This filter would perform two lookups:

  1. Find all ObjectChanges with the specified request ID pertaining to site objects, and return a list containing the ID of each site.
  2. Return a queryset containing all sites matched by the list of IDs.

Although we're making two queries, overhead shouldn't be too bad as the first is returning only the related object IDs. However we probably want to add a database index for the request_id column.

(I'm open to suggestions regarding the specific filter name. I'd like to avoid using the term "change request" as that could be very confusing to the user.)

Use case

The initial catalyst for this idea came from #10242, which seeks to optimize our approach for returning newly-imported objects. However, this functionality will likely find many additional use cases.

Shout-out to @DanSheps who first proposed this strategy.

Database changes

Add an index for extras_objectchange.request_id to optimize queries. This can be accomplished using a simple migration.

External dependencies

No response

Originally created by @jeremystretch on GitHub (Jan 13, 2023). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.4.2 ### Feature type New functionality ### Proposed functionality Add new filters to `NetBoxModelFilterSet` which enable a user to filter for objects based on the ID and action of an associated change record. For example, suppose you want to find all sites that were created as the result of a specific request. This proposal would enable you to filter send a request such as: ``` GET /dcim/sites/?objectchange_request_id=e39c84bc-f169-4d5f-bc1c-94487a1b18b5 ``` This filter would perform two lookups: 1. Find all ObjectChanges with the specified request ID pertaining to site objects, and return a list containing the ID of each site. 2. Return a queryset containing all sites matched by the list of IDs. Although we're making two queries, overhead shouldn't be too bad as the first is returning only the related object IDs. However we probably want to add a database index for the `request_id` column. (I'm open to suggestions regarding the specific filter name. I'd like to avoid using the term "change request" as that could be very confusing to the user.) ### Use case The initial catalyst for this idea came from #10242, which seeks to optimize our approach for returning newly-imported objects. However, this functionality will likely find many additional use cases. Shout-out to @DanSheps who first [proposed this strategy](https://github.com/netbox-community/netbox/issues/10242#issuecomment-1238552021). ### Database changes Add an index for `extras_objectchange.request_id` to optimize queries. This can be accomplished using a simple migration. ### External dependencies _No response_
adam added the status: acceptedtype: feature labels 2025-12-29 20:24:30 +01:00
adam closed this issue 2025-12-29 20:24:30 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7510