Attempting to delete all child prefixes from a parent prefixes does not properly filter prefixes to be deleted #1372

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

Originally created by @jeremystretch on GitHub (Nov 1, 2017).

Issue type

[ ] Feature request
[x] Bug report
[ ] Documentation

Environment

  • Python version: 3.5.2
  • NetBox version: 2.2.4

Description

To recreate:

  1. Create a parent prefix and enough child prefixes within it to paginate the results (51+ with the default pagination settings)
  2. From the parent prefix view, click the top checkbox in the child prefixes table to select all prefixes
  3. Check the "select all n prefixes matching query" option and click the "delete all" button at right
  4. The confirmation form lists all prefixes in NetBox, rather than only the child prefixes
Originally created by @jeremystretch on GitHub (Nov 1, 2017). ### Issue type [ ] Feature request <!-- Requesting the implementation of a new feature --> [x] Bug report <!-- Reporting unexpected or erroneous behavior --> [ ] Documentation <!-- Proposing a modification to the documentation --> ### Environment * Python version: 3.5.2 * NetBox version: 2.2.4 ### Description To recreate: 1. Create a parent prefix and enough child prefixes within it to paginate the results (51+ with the default pagination settings) 2. From the parent prefix view, click the top checkbox in the child prefixes table to select all prefixes 3. Check the "select all _n_ prefixes matching query" option and click the "delete all" button at right 4. The confirmation form lists _all_ prefixes in NetBox, rather than only the child prefixes
adam added the type: bug label 2025-12-29 16:31:51 +01:00
adam closed this issue 2025-12-29 16:31:52 +01:00
Author
Owner

@huzichunjohn commented on GitHub (Nov 2, 2017):

--- a/netbox/ipam/filters.py
+++ b/netbox/ipam/filters.py
@@ -183,7 +183,7 @@ class PrefixFilter(CustomFieldFilterSet, django_filters.FilterSet):
             return queryset
         try:
             query = str(IPNetwork(value).cidr)
-            return queryset.filter(prefix__net_contained_or_equal=query)
+            return queryset.filter(prefix__net_contained=query)
         except (AddrFormatError, ValueError):
             return queryset.none()
 
diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py
index 48e7e84..4251357 100644
--- a/netbox/ipam/views.py
+++ b/netbox/ipam/views.py
@@ -492,6 +492,7 @@ class PrefixView(View):
             'site', 'vlan', 'role',
         ).annotate_depth(limit=0)
         if child_prefixes:
+           child_prefix_count = len(child_prefixes)
             child_prefixes = add_available_prefixes(prefix.prefix, child_prefixes)
         child_prefix_table = tables.PrefixDetailTable(child_prefixes)
         if request.user.has_perm('ipam.change_prefix') or request.user.has_perm('ipam.delete_prefix'):
@@ -519,6 +520,8 @@ class PrefixView(View):
             'duplicate_prefix_table': duplicate_prefix_table,
             'permissions': permissions,
             'return_url': prefix.get_absolute_url(),
+           'bulk_querystring': 'parent={}'.format(prefix.prefix),
+           'obj_num': child_prefix_count,
         })
 
 
diff --git a/netbox/templates/utilities/obj_table.html b/netbox/templates/utilities/obj_table.html
index 058c7ef..38fd52d 100644
--- a/netbox/templates/utilities/obj_table.html
+++ b/netbox/templates/utilities/obj_table.html
@@ -9,7 +9,7 @@
                     <div class="checkbox-inline">
                         <label for="select_all">
                             <input type="checkbox" id="select_all" name="_all" />
-                            Select <strong>all {{ table.rows|length }} {{ table.data.verbose_name_plural }}</strong> matching query
+                            Select <strong>all {% if obj_num %}{{ obj_num }}{% else %}{{ table.rows|length }}{% endif %} {{ table.dat
                         </label>
                     </div>
                     <div class="pull-right">
@huzichunjohn commented on GitHub (Nov 2, 2017): ```diff --- a/netbox/ipam/filters.py +++ b/netbox/ipam/filters.py @@ -183,7 +183,7 @@ class PrefixFilter(CustomFieldFilterSet, django_filters.FilterSet): return queryset try: query = str(IPNetwork(value).cidr) - return queryset.filter(prefix__net_contained_or_equal=query) + return queryset.filter(prefix__net_contained=query) except (AddrFormatError, ValueError): return queryset.none() diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index 48e7e84..4251357 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -492,6 +492,7 @@ class PrefixView(View): 'site', 'vlan', 'role', ).annotate_depth(limit=0) if child_prefixes: + child_prefix_count = len(child_prefixes) child_prefixes = add_available_prefixes(prefix.prefix, child_prefixes) child_prefix_table = tables.PrefixDetailTable(child_prefixes) if request.user.has_perm('ipam.change_prefix') or request.user.has_perm('ipam.delete_prefix'): @@ -519,6 +520,8 @@ class PrefixView(View): 'duplicate_prefix_table': duplicate_prefix_table, 'permissions': permissions, 'return_url': prefix.get_absolute_url(), + 'bulk_querystring': 'parent={}'.format(prefix.prefix), + 'obj_num': child_prefix_count, }) diff --git a/netbox/templates/utilities/obj_table.html b/netbox/templates/utilities/obj_table.html index 058c7ef..38fd52d 100644 --- a/netbox/templates/utilities/obj_table.html +++ b/netbox/templates/utilities/obj_table.html @@ -9,7 +9,7 @@ <div class="checkbox-inline"> <label for="select_all"> <input type="checkbox" id="select_all" name="_all" /> - Select <strong>all {{ table.rows|length }} {{ table.data.verbose_name_plural }}</strong> matching query + Select <strong>all {% if obj_num %}{{ obj_num }}{% else %}{{ table.rows|length }}{% endif %} {{ table.dat </label> </div> <div class="pull-right"> ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1372