Repository: netbox-community/netbox

Issue:
Prefixes list from Aggregates list does not work
### NetBox version

v3.3.2

### Python version

3.8

### Steps to Reproduce

Add Aggregate 192.168.0.0/21
Add Prefix 192.168.0.0/24
Go to Aggregates and open the Aggregate 192.168.0.0/21, and then click "Prefixes"



### Expected Behavior

There should be a list of prefixes beloging to 192.168.0.0/21, in this case 192.168.0.0/24

By creating additional "Container" status type of prefix 192.168.0.0/21, there is the expected behavior.


### Observed Behavior

The outcome is:
--------
Server Error
There was a problem with your request. Please contact an administrator.

The complete exception is provided below:

<class 'django.urls.exceptions.NoReverseMatch'>

Reverse for 'prefix' with arguments '(None,)' not found. 1 pattern(s) tried: ['ipam/prefixes/(?P<pk>[0-9]+)/\\Z']

Python version: 3.8.10
NetBox version: 3.3.2
---------

By creating additional "Container" status type of prefix 192.168.0.0/21, there is the expected behavior.
![prefix_error](https://user-images.githubusercontent.com/91075161/188440343-750b2309-4936-4975-8b26-b4f1acb8a0b1.PNG)



Discussion:
Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v3.3.2. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.
I updated to 3.3.2 yesterday and am now seeing this behavior on some prefixes, though not all. I'm still looking for a pattern. Here's a small sample of our structure.

![image](https://user-images.githubusercontent.com/63061459/188659904-5a404a61-4180-4b91-977e-4bfc20eb10db.png)

If I then select either the 10.0.0.0/8 prefix or the 10.0.0.0/13 prefix and then select the child prefixes tab, I get the same error provided by @zuokot 

![image](https://user-images.githubusercontent.com/63061459/188660272-737ca134-d35a-4a20-9000-3b648512ec4c.png)
![image](https://user-images.githubusercontent.com/63061459/188660310-fea0af50-eb02-438d-86a2-363dff0ed288.png)


EDIT:
I'm also attaching the error I've extracted from the server that provides the full traceback.
[netbox_10259_error.txt](https://github.com/netbox-community/netbox/files/9499458/netbox_10259_error.txt)

Hi, 
Interesting founding which corrected the issue.
On the "Prefixes" page there is for some reason a header column "Prefix (flat)" chosen instead of "Prefix" and as soon as changed it back to "Prefix", the problem disappeared. 

![prefixes_headers](https://user-images.githubusercontent.com/91075161/188913652-58ff5593-ad41-4b21-affb-56ba577bc490.PNG)


Resolving patch:
diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py
--- a/netbox/ipam/tables/ip.py
+++ b/netbox/ipam/tables/ip.py
@@ -21,6 +21,14 @@
 AVAILABLE_LABEL = mark_safe('<span class="badge bg-success">Available</span>')
 
 PREFIX_LINK = """
+{% if record.pk %}
+  <a href="{{ record.get_absolute_url }}">{{ record.prefix }}</a>
+{% else %}
+  <a href="{% url 'ipam:prefix_add' %}?prefix={{ record }}{% if object.vrf %}&vrf={{ object.vrf.pk }}{% endif %}{% if object.site %}&site={{ object.site.pk }}{% endif %}{% if object.tenant %}&tenant_group={{ object.tenant.group.pk }}&tenant={{ object.tenant.pk }}{% endif %}">{{ record.prefix }}</a>
+{% endif %}
+"""
+
+PREFIX_LINK_WITH_DEPTH = """
 {% load helpers %}
 {% if record.depth %}
     <div class="record-depth">
@@ -29,8 +37,7 @@
         {% endfor %}
     </div>
 {% endif %}
-<a href="{% if record.pk %}{% url 'ipam:prefix' pk=record.pk %}{% else %}{% url 'ipam:prefix_add' %}?prefix={{ record }}{% if object.vrf %}&vrf={{ object.vrf.pk }}{% endif %}{% if object.site %}&site={{ object.site.pk }}{% endif %}{% if object.tenant %}&tenant_group={{ object.tenant.group.pk }}&tenant={{ object.tenant.pk }}{% endif %}{% endif %}">{{ record.prefix }}</a>
-"""
+""" + PREFIX_LINK
 
 IPADDRESS_LINK = """
 {% if record.pk %}
@@ -216,14 +223,15 @@ class PrefixUtilizationColumn(columns.UtilizationColumn):
 
 class PrefixTable(TenancyColumnsMixin, NetBoxTable):
     prefix = columns.TemplateColumn(
-        template_code=PREFIX_LINK,
+        template_code=PREFIX_LINK_WITH_DEPTH,
         export_raw=True,
         attrs={'td': {'class': 'text-nowrap'}}
     )
-    prefix_flat = tables.Column(
+    prefix_flat = columns.TemplateColumn(
         accessor=Accessor('prefix'),
-        linkify=True,
-        verbose_name='Prefix (Flat)',
+        template_code=PREFIX_LINK,
+        export_raw=True,
+        verbose_name='Prefix (Flat)'
     )
     depth = tables.Column(
         accessor=Accessor('_depth'),


Test patch: