Standardize filtering logic for the parents of recursively-nested models #15383
Labels
breaking change
This change modifies or removes some previously documented functionality
status: accepted
This issue has been accepted for implementation
type: feature
Introduction of new functionality to the application
Milestone
NetBox version
v3.7.3
Feature type
Change to existing functionality
Proposed functionality
I'm opening this FR to address an inconsistency in the filtering of parent objects of self-recursive models (e.g. regions, site groups, locations, etc.).
For most of these objects, filtering by the parent object will return only the immediate children of the specified parent. For example, filtering for all regions belonging to North America (PK 1) will return only the countries assigned to that continent; it will not include child states or cities within each country.
However, this is not true for locations. Per #6124, filtering locations by a parent location will return all of the parent object's descendants. For example, if dealing with a hierarchy of buildings, floors, and rooms, filtering for a specific building will return both rooms and floors within it.
I am proposing a two-part change:
parent
&parent_id
filters so that they behave consistently across all nested models. (This will likely mean modifying the current behavior of the location filter, as it would be the smallest breaking change.)ancestor
).Edit: For example, you could then do
to return only the immediate children of region 1, OR
to return all regions within region 1.
Use case
Neither behavior described above is objectively correct or incorrect: Both have valid use cases. However, we should address the inconsistency and prescribe a clear mechanism for achieving either behavior for all relevant models.
Database changes
None expected
External dependencies
None
The text was updated successfully, but these errors were encountered: