internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: netbox-community/netbox

Issue:
Search tags by their description
### NetBox version

v3.1.7

### Feature type

Change to existing functionality

### Proposed functionality

Allow the search bar at the Tags page to also search through the Description column.

### Use case

One use case for tags is for identifying VLANs and, in our use case, they are abbreviated, e.g., `NWPT` stands for **New Port**.
We'd like to be able to search for the term **New Port**, which is in the `Description` field, without needing to use the browser's  `Ctrl+F`.

### Database changes

None.

### External dependencies

N/A


Discussion:

Resolving patch:
diff --git a/netbox/extras/filtersets.py b/netbox/extras/filtersets.py
--- a/netbox/extras/filtersets.py
+++ b/netbox/extras/filtersets.py
@@ -184,7 +184,8 @@ def search(self, queryset, name, value):
             return queryset
         return queryset.filter(
             Q(name__icontains=value) |
-            Q(slug__icontains=value)
+            Q(slug__icontains=value) |
+            Q(description__icontains=value)
         )
 
     def _content_type(self, queryset, name, values):


Test patch:
Repository: netbox-community/netbox

Issue:
Search bar contents not retained after submitting
### NetBox version

v3.1.8

### Python version

3.8

### Steps to Reproduce

1. Enter a search term into the main search bar and submit
2. See empty search bar

### Expected Behavior

1. Enter a search term into the main search bar and submit
2. Search term should still be present

### Observed Behavior

1. Enter a search term into the main search bar and submit
2. Search bar is empty


Discussion:
I've been wanting to submit a FR for this, but always forgot about it :-)
Maybe a good one to combine with #7839 (set input focus on searchbar )

I have a PR for this ready.. @jeremystretch can you assign this to me ?

Resolving patch:
diff --git a/netbox/utilities/templatetags/search.py b/netbox/utilities/templatetags/search.py
--- a/netbox/utilities/templatetags/search.py
+++ b/netbox/utilities/templatetags/search.py
@@ -8,6 +8,9 @@
 
 
 @register.inclusion_tag("search/searchbar.html")
-def search_options() -> Dict:
+def search_options(request) -> Dict:
     """Provide search options to template."""
-    return {"options": search_form.options}
+    return {
+        'options': search_form.options,
+        'request': request,
+    }


Test patch:
Repository: netbox-community/netbox

Issue:
Script list is slow when having large script files/a lot of scripts
### NetBox version

v3.1.9

### Python version

3.9

### Steps to Reproduce

1. Create script file with following content in the script directory (test1.py): [content](https://gist.github.com/kkthxbye-code/75aa97e2fc5506da999bb6b01b3c1ed8)
2. Duplicate it a bunch of times: `for i in {2..20}; do cp test1.py "test$i.py"; done`
3. Open the script list view - `/extras/scripts/`

### Expected Behavior

Load times should not be multiple seconds

### Observed Behavior

On my i7 9700 the load times are roughly 2.3 seconds for the above example. On our production server (weaker single core performance) the performance impact is larger.

I have implemented a fix (https://github.com/netbox-community/netbox/pull/8925) which reduces the load time for the reproduction example from ~2300 ms to ~160 ms.


Discussion:

Resolving patch:
diff --git a/netbox/extras/scripts.py b/netbox/extras/scripts.py
--- a/netbox/extras/scripts.py
+++ b/netbox/extras/scripts.py
@@ -259,6 +259,10 @@ class BaseScript:
     Base model for custom scripts. User classes should inherit from this model if they want to extend Script
     functionality for use in other subclasses.
     """
+
+    # Prevent django from instantiating the class on all accesses
+    do_not_call_in_templates = True
+
     class Meta:
         pass
 
@@ -280,7 +284,7 @@ def __str__(self):
 
     @classproperty
     def name(self):
-        return getattr(self.Meta, 'name', self.__class__.__name__)
+        return getattr(self.Meta, 'name', self.__name__)
 
     @classproperty
     def full_name(self):


Test patch:
Repository: netbox-community/netbox

Issue:
Create a template filter to linkify objects
### Proposed Changes

Introduce a `linkify` template filter that will render a link to an object. For example,

```
{{ object|linkify }}
```

would be equivalent to

```
<a href="{{ object.get_absolute_url }}">{{ object }}</a>
```

If `object` does not have a `get_absolute_url()` method, the filter returns the string representation of `object`, or None.

### Justification

There's a common pattern in templates where we want to link to an object as its string representation. For example:

```
<a href="{{ object.attr.get_absolute_url }}">{{ object.attr }}</a>
```

While this isn't terribly obtuse, it can get a bit ugly when we introduce a conditional:

```
{% if object.attr %}
    <a href="{{ object.attr.get_absolute_url }}">{{ object.attr }}</a>
{% else %}
    {{ ''|placeholder }}
{% endif %}
```

With a `linkify` filter in place, we could just do:

```
{{ object.attr|linkify|placeholder }}
```


Discussion:

Resolving patch:
diff --git a/netbox/utilities/templatetags/builtins/filters.py b/netbox/utilities/templatetags/builtins/filters.py
--- a/netbox/utilities/templatetags/builtins/filters.py
+++ b/netbox/utilities/templatetags/builtins/filters.py
@@ -20,6 +20,26 @@
 # General
 #
 
+@register.filter()
+def linkify(instance, attr=None):
+    """
+    Render a hyperlink for an object with a `get_absolute_url()` method, optionally specifying the name of an
+    attribute to use for the link text. If no attribute is given, the object's string representation will be
+    used.
+
+    If the object has no `get_absolute_url()` method, return the text without a hyperlink element.
+    """
+    if instance is None:
+        return ''
+
+    text = getattr(instance, attr) if attr is not None else str(instance)
+    try:
+        url = instance.get_absolute_url()
+        return mark_safe(f'<a href="{url}">{text}</a>')
+    except (AttributeError, TypeError):
+        return text
+
+
 @register.filter()
 def bettertitle(value):
     """


Test patch:
Repository: netbox-community/netbox

Issue:
Using wildcards in DNS names
### NetBox version

v3.1.8

### Python version

3.9

### Steps to Reproduce

This is a copy of https://github.com/netbox-community/netbox/issues/4973 because I can't comment there, but the issue is not resolved.

1. Edit IP Address in IPAM
2. Try to save with * in DNS name like: "*.example.local"

Like in https://github.com/netbox-community/netbox/issues/3722 the regex needs to be adjusted.

### Expected Behavior

IP address saved correctly.
https://en.wikipedia.org/wiki/Wildcard_DNS_record

### Observed Behavior

Error: "Only alphanumeric characters, hyphens, periods, and underscores are allowed in DNS names"


Discussion:
It appears that you have duplicated #4973, which was closed due to lack of community interest. Are you interested in owning this change and contributing a PR for it?

Also, this needs to be resubmitted as a feature request, not a bug, as the current behavior is expected.
Yes, it's a duplicate as mentioned above. Well, I'm interested in getting this fixed, and also a wildcard is valid in dns records, so the validator should accept it.
My Python foo isn't strong, but I'll try to create a PR and submit it as a feature request.
Thanks for letting me know about the correct workflow.

Resolving patch:
diff --git a/netbox/ipam/validators.py b/netbox/ipam/validators.py
--- a/netbox/ipam/validators.py
+++ b/netbox/ipam/validators.py
@@ -24,7 +24,7 @@ def compare(self, a, b):
 
 
 DNSValidator = RegexValidator(
-    regex='^[0-9A-Za-z._-]+$',
-    message='Only alphanumeric characters, hyphens, periods, and underscores are allowed in DNS names',
+    regex=r'^([0-9A-Za-z_-]+|\*)(\.[0-9A-Za-z_-]+)*\.?$',
+    message='Only alphanumeric characters, asterisks, hyphens, periods, and underscores are allowed in DNS names',
     code='invalid'
 )


Test patch:
Repository: netbox-community/netbox

Issue:
Devices with Images on the rear side are not clickable in the rack view svg.
### NetBox version

v3.1.9

### Python version

3.9

### Steps to Reproduce

1. create a rack
2. create a full-depth device type
3. add front and read pictures to the device type
4. create a device with the created device type in the rack
5. look at the front and rear of the device in the SVG with images enabled.

### Expected Behavior

Front as well as rear should have a link to the device, independently of whether images are shown or not.

### Observed Behavior

Only the front can be clicked. When only labels are show the Link can be clicked.


Discussion:
This was introduced by me in https://github.com/netbox-community/netbox/pull/8592
https://github.com/netbox-community/netbox/issues/7150#issuecomment-1049703267

I will shortly open a PR to fix this.

Resolving patch:
diff --git a/netbox/dcim/svg.py b/netbox/dcim/svg.py
--- a/netbox/dcim/svg.py
+++ b/netbox/dcim/svg.py
@@ -146,10 +146,10 @@ def _draw_device_rear(self, drawing, device, start, end, text):
                 class_='device-image'
             )
             image.fit(scale='slice')
-            drawing.add(image)
-            drawing.add(drawing.text(get_device_name(device), insert=text, stroke='black',
-                        stroke_width='0.2em', stroke_linejoin='round', class_='device-image-label'))
-            drawing.add(drawing.text(get_device_name(device), insert=text, fill='white', class_='device-image-label'))
+            link.add(image)
+            link.add(drawing.text(get_device_name(device), insert=text, stroke='black',
+                     stroke_width='0.2em', stroke_linejoin='round', class_='device-image-label'))
+            link.add(drawing.text(get_device_name(device), insert=text, fill='white', class_='device-image-label'))
 
     @staticmethod
     def _draw_empty(drawing, rack, start, end, text, id_, face_id, class_, reservation):


Test patch:
Repository: netbox-community/netbox

Issue:
Additional Fields in Device Bay Table
### NetBox version

v3.1.6

### Feature type

New functionality

### Proposed functionality

We would like to see additional fields within the Device Bays table. In particular, we want to introduce the following fields:
  - Device Type
  - Device Role 

We are also happy to provide the needed PR for this feature!

![Screenshot from 2022-03-21 12-36-24](https://user-images.githubusercontent.com/12380026/159253889-a6a95317-45c3-424f-9739-41600516e7b2.png)


### Use case

We use housings for some devices, which have different types and roles. Therefore a housing can contain various different device types and roles. In the device bay overview, we cannot view the different types and roles within the housing. This results in each device having to be viewed individually to see the type and/or role of the device. We want to resolve this problem to provide a better user experience.

### Database changes

None

### External dependencies

None


Discussion:

Resolving patch:
diff --git a/netbox/dcim/tables/devices.py b/netbox/dcim/tables/devices.py
--- a/netbox/dcim/tables/devices.py
+++ b/netbox/dcim/tables/devices.py
@@ -677,6 +677,15 @@ class DeviceBayTable(DeviceComponentTable):
             'args': [Accessor('device_id')],
         }
     )
+    device_role = ColoredLabelColumn(
+        accessor=Accessor('installed_device__device_role'),
+        verbose_name='Role'
+    )
+    device_type = tables.Column(
+        accessor=Accessor('installed_device__device_type'),
+        linkify=True,
+        verbose_name='Type'
+    )
     status = tables.TemplateColumn(
         template_code=DEVICEBAY_STATUS,
         order_by=Accessor('installed_device__status')
@@ -691,7 +700,7 @@ class DeviceBayTable(DeviceComponentTable):
     class Meta(DeviceComponentTable.Meta):
         model = DeviceBay
         fields = (
-            'pk', 'id', 'name', 'device', 'label', 'status', 'installed_device', 'description', 'tags',
+            'pk', 'id', 'name', 'device', 'label', 'status', 'device_role', 'device_type', 'installed_device', 'description', 'tags',
             'created', 'last_updated',
         )
 


Test patch:
Repository: netbox-community/netbox

Issue:
Bridge members panel in interface view
### NetBox version

v3.1.2

### Feature type

Change to existing functionality

### Proposed functionality

When viewing interface details (e.g. `/dcim/interfaces/3141/`), there is a section for Child interfaces (i.e. other interfaces whose Parent points at this one), and a panel for LAG Members if the interface is a LAG.  But bridge members are not shown.

I propose that if the interface type is "Bridge" then a Bridge Members panel is added - similar to the "LAG Members" panel - showing interfaces whose Bridge attribute points at this interface.

### Use case

Be able to see and navigate to bridge member interfaces.  Consistency with LAG member interfaces.

Workaround: you can manually enter URL `/dcim/interfaces/?bridge_id=3141`

### Database changes

None

### External dependencies

None


Discussion:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
I can try to implement this

Resolving patch:
diff --git a/netbox/dcim/models/device_components.py b/netbox/dcim/models/device_components.py
--- a/netbox/dcim/models/device_components.py
+++ b/netbox/dcim/models/device_components.py
@@ -762,6 +762,10 @@ def is_wireless(self):
     def is_lag(self):
         return self.type == InterfaceTypeChoices.TYPE_LAG
 
+    @property
+    def is_bridge(self):
+        return self.type == InterfaceTypeChoices.TYPE_BRIDGE
+
     @property
     def link(self):
         return self.cable or self.wireless_link
diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py
--- a/netbox/dcim/views.py
+++ b/netbox/dcim/views.py
@@ -1776,6 +1776,14 @@ def get_extra_context(self, request, instance):
             orderable=False
         )
 
+        # Get bridge interfaces
+        bridge_interfaces = Interface.objects.restrict(request.user, 'view').filter(bridge=instance)
+        bridge_interfaces_tables = tables.InterfaceTable(
+            bridge_interfaces,
+            exclude=('device', 'parent'),
+            orderable=False
+        )
+
         # Get child interfaces
         child_interfaces = Interface.objects.restrict(request.user, 'view').filter(parent=instance)
         child_interfaces_tables = tables.InterfaceTable(
@@ -1800,6 +1808,7 @@ def get_extra_context(self, request, instance):
 
         return {
             'ipaddress_table': ipaddress_table,
+            'bridge_interfaces_table': bridge_interfaces_tables,
             'child_interfaces_table': child_interfaces_tables,
             'vlan_table': vlan_table,
         }


Test patch:
Repository: netbox-community/netbox

Issue:
Filtering for child devices by parent device
### NetBox version

v3.1.5

### Feature type

Change to existing functionality

### Proposed functionality

I think a query option to identify all child devices of a parent device would be a good enhancement. For example to find all blade server associated with an enclosure or all network modules of a networking device. From the Web UI it's currently ok to get such overview by selecting a parent device and look on the device-bay tab for the child devices.
To get such overview from the REST API is currently more tricky. First you have to identify the device id of the parent device. Next it's necessary to get all devices which may be associated with the parent device and filter the JSON for results[].parent_device.id .


### Use case

Being able to query child devices by parent_device_id on the API call, would make some automation tasks more easy to realize. In addition it should slightly reduce the load on the app server, since it's no more necessary to make queries with large result sets.

### Database changes

None that I'm aware of.

### External dependencies

None


Discussion:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
I can try to implement this
@stephanblanke are you still interested in working on this?

Resolving patch:
diff --git a/netbox/dcim/filtersets.py b/netbox/dcim/filtersets.py
--- a/netbox/dcim/filtersets.py
+++ b/netbox/dcim/filtersets.py
@@ -639,6 +639,11 @@ class DeviceFilterSet(PrimaryModelFilterSet, TenancyFilterSet, ContactModelFilte
         to_field_name='slug',
         label='Role (slug)',
     )
+    parent_device_id = django_filters.ModelMultipleChoiceFilter(
+        field_name='parent_bay__device',
+        queryset=Device.objects.all(),
+        label='Parent Device (ID)',
+    )
     platform_id = django_filters.ModelMultipleChoiceFilter(
         queryset=Platform.objects.all(),
         label='Platform (ID)',


Test patch:
Repository: netbox-community/netbox

Issue:
Limit the number of non-racked devices that are listed on the Site and Location pages
### NetBox version

netbox-84cb8b95fd-dcfw8 (v3.2.0-beta2)

### Feature type

Change to existing functionality

### Proposed functionality

Only show a small number (10 or so) of non-racked devices on site and location pages. Include a link that would take you to a device search with pre-populated search that limits the devices shown to that site/location and have not been assigned to a rack.



### Use case

Currently, when you view a site or a location in NetBox, it will list all of the non-racked devices that have been assigned to that site or location. If you have a lot of non-racked devices, the page can take a very long time to generate and is very unwieldy to use. By linking to a device search, you can use the paging functionality or further narrow the search parameters.

### Database changes

None

### External dependencies

None


Discussion:
This sounds like it would be addressed by #8184 (allowing the user to paginate through the table without leaving the page).
@jeremystretch Is this FR approved in it's current form or are you suggesting only #8184 could close it?

I'm happy to pick it up in it's current form if so.
@jasonyates both. I think it makes sense in the immediate term to limit the number of devices listed, and once #8184 is in place it will no longer be necessary to do so.

I'll assign this to you, thanks!

Resolving patch:
diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py
--- a/netbox/dcim/views.py
+++ b/netbox/dcim/views.py
@@ -342,6 +342,7 @@ def get_extra_context(self, request, instance):
             'device_count',
             cumulative=True
         ).restrict(request.user, 'view').filter(site=instance)
+
         nonracked_devices = Device.objects.filter(
             site=instance,
             position__isnull=True,
@@ -357,7 +358,8 @@ def get_extra_context(self, request, instance):
             'stats': stats,
             'locations': locations,
             'asns': asns,
-            'nonracked_devices': nonracked_devices,
+            'nonracked_devices': nonracked_devices.order_by('-pk')[:10],
+            'total_nonracked_devices_count': nonracked_devices.count(),
         }
 
 
@@ -435,6 +437,7 @@ def get_extra_context(self, request, instance):
         ).filter(pk__in=location_ids).exclude(pk=instance.pk)
         child_locations_table = tables.LocationTable(child_locations)
         child_locations_table.configure(request)
+
         nonracked_devices = Device.objects.filter(
             location=instance,
             position__isnull=True,
@@ -445,7 +448,8 @@ def get_extra_context(self, request, instance):
             'rack_count': rack_count,
             'device_count': device_count,
             'child_locations_table': child_locations_table,
-            'nonracked_devices': nonracked_devices,
+            'nonracked_devices': nonracked_devices.order_by('-pk')[:10],
+            'total_nonracked_devices_count': nonracked_devices.count(),
         }
 
 


Test patch:
Repository: netbox-community/netbox

Issue:
Show full usernames when filtering
### NetBox version

v3.1.9

### Feature type

Change to existing functionality

### Proposed functionality

When using the filters to filter user-based (e.g. Journal and Changelog), the full user name should be displayed in brackets, instead of just the login name.

### Use case

Makes filtering in big installations easier

### Database changes

None, all data is already in netbox

### External dependencies

None


Discussion:
Currently:
![grafik](https://user-images.githubusercontent.com/18295403/158780465-0b1fbbdb-79f4-46cd-b349-4208b2cf7037.png)
Proposed:
![Unbenannt](https://user-images.githubusercontent.com/18295403/158782389-90a151f6-3caf-4f39-bdec-c3b6ca48506b.png)



Resolving patch:
diff --git a/netbox/users/api/nested_serializers.py b/netbox/users/api/nested_serializers.py
--- a/netbox/users/api/nested_serializers.py
+++ b/netbox/users/api/nested_serializers.py
@@ -28,6 +28,11 @@ class Meta:
         model = User
         fields = ['id', 'url', 'display', 'username']
 
+    def get_display(self, obj):
+        if full_name := obj.get_full_name():
+            return f"{obj.username} ({full_name})"
+        return obj.username
+
 
 class NestedTokenSerializer(WritableNestedSerializer):
     url = serializers.HyperlinkedIdentityField(view_name='users-api:token-detail')
diff --git a/netbox/users/api/serializers.py b/netbox/users/api/serializers.py
--- a/netbox/users/api/serializers.py
+++ b/netbox/users/api/serializers.py
@@ -44,6 +44,11 @@ def create(self, validated_data):
         user.save()
 
         return user
+    
+    def get_display(self, obj):
+        if full_name := obj.get_full_name():
+            return f"{obj.username} ({full_name})"
+        return obj.username
 
 
 class GroupSerializer(ValidatedModelSerializer):


Test patch: