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

Issue:
L2VPN Bulk import not setting Tenant field
### NetBox version

v3.4.7

### Python version

3.8

### Steps to Reproduce

1. Go to Overlay -> L2VPNs
2. Click the 'Import' button
3. Fill the Data Import text field with data that has `tenant` column populated
4. Submit the form

### Expected Behavior

Imported L2VPNs should have Tenant specified in `tenant` field linked to it.

### Observed Behavior

Imported L2VPNs do not belong to any Tenant, as if the `tenant` field was not specified. 


Discussion:

Resolving patch:
diff --git a/netbox/ipam/forms/bulk_import.py b/netbox/ipam/forms/bulk_import.py
--- a/netbox/ipam/forms/bulk_import.py
+++ b/netbox/ipam/forms/bulk_import.py
@@ -443,7 +443,8 @@ class L2VPNImportForm(NetBoxModelImportForm):
 
     class Meta:
         model = L2VPN
-        fields = ('identifier', 'name', 'slug', 'type', 'description', 'comments', 'tags')
+        fields = ('identifier', 'name', 'slug', 'tenant', 'type', 'description',
+                  'comments', 'tags')
 
 
 class L2VPNTerminationImportForm(NetBoxModelImportForm):


Test patch:
Repository: netbox-community/netbox

Issue:
globalsearch: search result view: ordering results by object_type not working
### NetBox version

v3.4.2

### Python version

3.10

### Steps to Reproduce

goto: https://demo.netbox.dev/search/?q=100
press "Type" on the search results table header, results do not re-order

### Expected Behavior

objects to be grouped together by object type when sorted by object_type. instead "field" seems to take precidence

### Observed Behavior

Some of the same object types are split apart, eg on the demo site some of the device types are separated, also when you try and order in reverse the order does not seem to change.

In our internal instance we sometimes see devices intermingled with other objects. 

sorting by "field" works as expected, sorting by "type" does not and seems to fallback to sorting by "field"


Discussion:

Resolving patch:
diff --git a/netbox/netbox/tables/tables.py b/netbox/netbox/tables/tables.py
--- a/netbox/netbox/tables/tables.py
+++ b/netbox/netbox/tables/tables.py
@@ -200,7 +200,8 @@ def __init__(self, *args, extra_columns=None, **kwargs):
 
 class SearchTable(tables.Table):
     object_type = columns.ContentTypeColumn(
-        verbose_name=_('Type')
+        verbose_name=_('Type'),
+        order_by="object___meta__verbose_name",
     )
     object = tables.Column(
         linkify=True


Test patch:
Repository: netbox-community/netbox

Issue:
Enable markdown in custom field description fields and custom validator error messages
### NetBox version

v3.3.6

### Feature type

New functionality

### Proposed functionality

Enable markdown syntax on custom field descriptions and error messages in custom validators. Not all syntax options need to be supported; at least boldface, italics, and links.

### Use case

The ability to link to outside content (e.g. documentation) in either descriptions or error messages would be helpful. Formatting options like boldface and italics can make error messages easier to understand.

### Database changes

Possibly expand the maximum length of custom field description fields, as markdown syntax may significantly increase the value stored.

### 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. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
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. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
@jeremystretch Sorry, didn't see the needs owner tag. I'll take this, thanks.

Resolving patch:
diff --git a/netbox/extras/tables/tables.py b/netbox/extras/tables/tables.py
--- a/netbox/extras/tables/tables.py
+++ b/netbox/extras/tables/tables.py
@@ -29,6 +29,7 @@ class CustomFieldTable(NetBoxTable):
     content_types = columns.ContentTypesColumn()
     required = columns.BooleanColumn()
     ui_visibility = columns.ChoiceFieldColumn(verbose_name="UI visibility")
+    description = columns.MarkdownColumn()
     is_cloneable = columns.BooleanColumn()
 
     class Meta(NetBoxTable.Meta):


Test patch:
Repository: netbox-community/netbox

Issue:
Certain characters are incorrectly escaped when rendering custom links
### NetBox version

v3.4.9

### Python version

3.8

### Steps to Reproduce

1. Create a custom link with the URL `http://example.com/?foo=1&bar=2`
2. View an object where the custom link appears and inspect its source

### Expected Behavior

The unmodified URL should be present.

### Observed Behavior

The link is incorrectly escaped to `http://example.com/?foo%3D1&bar%3D2`. This is a regression resulting from 89fa546a1481e56d14cfc4d666a55482b0c85fd1.


Discussion:

Resolving patch:
diff --git a/netbox/extras/models/models.py b/netbox/extras/models/models.py
--- a/netbox/extras/models/models.py
+++ b/netbox/extras/models/models.py
@@ -279,7 +279,7 @@ def render(self, context):
         text = clean_html(text, allowed_schemes)
 
         # Sanitize link
-        link = urllib.parse.quote_plus(link, safe='/:?&')
+        link = urllib.parse.quote_plus(link, safe='/:?&=%+[]@#')
 
         # Verify link scheme is allowed
         result = urllib.parse.urlparse(link)


Test patch:
Repository: netbox-community/netbox

Issue:
Dashboard - Changelog can't be displayed
### NetBox version

v3.5.0

### Python version

3.8

### Steps to Reproduce

After an upgrade from 3.4.8, Default Widget displays "Change Log" in blue. I wanted to change the color

From demo website
![image](https://user-images.githubusercontent.com/64533932/235115868-08106e39-6fdb-428a-aad9-9cfd728ddbb1.png)

Editing the entry shows 
![image](https://user-images.githubusercontent.com/64533932/235116070-cfb83602-6124-4011-9d40-f964d0d678e3.png)

I can't find extras > changelog in "model"

### Expected Behavior

Extra > Changelog should be in the menu

### Observed Behavior

![image](https://user-images.githubusercontent.com/64533932/235116606-810e96d2-9fa5-43c6-aca7-97193f061781.png)



Discussion:
Caused by https://github.com/netbox-community/netbox/commit/8d6c591535e416e247f0cf3826570b7fd2b652bd

Resolving patch:
diff --git a/netbox/extras/dashboard/widgets.py b/netbox/extras/dashboard/widgets.py
--- a/netbox/extras/dashboard/widgets.py
+++ b/netbox/extras/dashboard/widgets.py
@@ -8,6 +8,7 @@
 from django.conf import settings
 from django.contrib.contenttypes.models import ContentType
 from django.core.cache import cache
+from django.db.models import Q
 from django.template.loader import render_to_string
 from django.urls import NoReverseMatch, reverse
 from django.utils.translation import gettext as _
@@ -33,7 +34,7 @@ def get_content_type_labels():
     return [
         (content_type_identifier(ct), content_type_name(ct))
         for ct in ContentType.objects.filter(
-            FeatureQuery('export_templates').get_query()
+            FeatureQuery('export_templates').get_query() | Q(app_label='extras', model='objectchange')
         ).order_by('app_label', 'model')
     ]
 


Test patch:
Repository: netbox-community/netbox

Issue:
Site filter does not apply when clicking on VLAN Groups from the Site view page
### NetBox version

v3.5.0

### Python version

3.8

### Steps to Reproduce

1. Open a site (eg. http://netbox/dcim/sites/1350/)
2. Click on VLAN Groups under Related Objects

### Expected Behavior

Only the VLAN Groups associated to that site should be displayed.

### Observed Behavior

All VLAN groups are shown.
It looks like the filter parameter in the URL is for site_id and it should be for site.
eg. should be http://netbox/ipam/vlan-groups/?site=1350 not http://netbox/ipam/vlan-groups/?site_id=1350


Discussion:

Resolving patch:
diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py
--- a/netbox/dcim/views.py
+++ b/netbox/dcim/views.py
@@ -371,7 +371,7 @@ def get_extra_context(self, request, instance):
             (VLANGroup.objects.restrict(request.user, 'view').filter(
                 scope_type=ContentType.objects.get_for_model(Site),
                 scope_id=instance.pk
-            ), 'site_id'),
+            ), 'site'),
             (VLAN.objects.restrict(request.user, 'view').filter(site=instance), 'site_id'),
             # Circuits
             (Circuit.objects.restrict(request.user, 'view').filter(terminations__site=instance).distinct(), 'site_id'),


Test patch:
Repository: netbox-community/netbox

Issue:
Circuit Provider Account field required API not in GUI
### NetBox version

v3.5.0

### Python version

3.8

### Steps to Reproduce

1. Use the REST API to create a new circuit
`
{
    "cid": "12345",
    "provider": 1,
    "type": 1,
}
`
Error: {"provider_account":["This field is required."]}
2. Use the GUI to add circuit, `provider_account` is an optional field
3. Try to add circuit with provider_account set as 0
`
{
    "cid": "12345",
    "provider": 1,
    "type": 1,
    "provider_account": 0
}
`
Error: {"provider_account":["Related object not found using the provided numeric ID: 0"]}
4. Read existing migrated circuit from netbox
` ...."provider_account":null ...
` 

### Expected Behavior

The circuit `provider_account` field should be optional in the RESTAPI as it current is in the GUI.

### Observed Behavior

Error was shown requiring the provider_account field to be defined


Discussion:
If you leave the provider_account out of the request entirely does it break? Because if it's not there, it should be null. But if you provide a value, that value needs to exist.

I.E. :
`{ "cid": "12345", "provider": 1, "type": 1 }`
Without provider_account it breaks indeed. See above step 1

Resolving patch:
diff --git a/netbox/circuits/api/serializers.py b/netbox/circuits/api/serializers.py
--- a/netbox/circuits/api/serializers.py
+++ b/netbox/circuits/api/serializers.py
@@ -106,7 +106,7 @@ class Meta:
 class CircuitSerializer(NetBoxModelSerializer):
     url = serializers.HyperlinkedIdentityField(view_name='circuits-api:circuit-detail')
     provider = NestedProviderSerializer()
-    provider_account = NestedProviderAccountSerializer()
+    provider_account = NestedProviderAccountSerializer(required=False, allow_null=True)
     status = ChoiceField(choices=CircuitStatusChoices, required=False)
     type = NestedCircuitTypeSerializer()
     tenant = NestedTenantSerializer(required=False, allow_null=True)
diff --git a/netbox/circuits/forms/bulk_import.py b/netbox/circuits/forms/bulk_import.py
--- a/netbox/circuits/forms/bulk_import.py
+++ b/netbox/circuits/forms/bulk_import.py
@@ -74,7 +74,8 @@ class CircuitImportForm(NetBoxModelImportForm):
     provider_account = CSVModelChoiceField(
         queryset=ProviderAccount.objects.all(),
         to_field_name='name',
-        help_text=_('Assigned provider account')
+        help_text=_('Assigned provider account'),
+        required=False
     )
     type = CSVModelChoiceField(
         queryset=CircuitType.objects.all(),


Test patch:
Repository: netbox-community/netbox

Issue:
Report result do not update in API
### NetBox version

v.3.5.0

### Python version

3.10

### Steps to Reproduce

1. Run a Report
2. Check Report status in API

### Expected Behavior

New report status is reported in the API

### Observed Behavior

Last report status prior to 3.5 Upgrade is returned.


Discussion:
In [netbox/extras/api/views.py#L186](https://github.com/netbox-community/netbox/blob/develop/netbox/extras/api/views.py#L186) the report jobs are filterd differently then in [get_latest_jobs](https://github.com/netbox-community/netbox/blob/develop/netbox/netbox/models/features.py#L313) which is used by the report view.

Resolving patch:
diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py
--- a/netbox/dcim/views.py
+++ b/netbox/dcim/views.py
@@ -398,32 +398,8 @@ def get_extra_context(self, request, instance):
             (Circuit.objects.restrict(request.user, 'view').filter(terminations__site=instance).distinct(), 'site_id'),
         )
 
-        locations = Location.objects.add_related_count(
-            Location.objects.all(),
-            Rack,
-            'location',
-            'rack_count',
-            cumulative=True
-        )
-        locations = Location.objects.add_related_count(
-            locations,
-            Device,
-            'location',
-            'device_count',
-            cumulative=True
-        ).restrict(request.user, 'view').filter(site=instance)
-
-        nonracked_devices = Device.objects.filter(
-            site=instance,
-            rack__isnull=True,
-            parent_bay__isnull=True
-        ).prefetch_related('device_type__manufacturer', 'parent_bay', 'device_role')
-
         return {
             'related_models': related_models,
-            'locations': locations,
-            'nonracked_devices': nonracked_devices.order_by('-pk')[:10],
-            'total_nonracked_devices_count': nonracked_devices.count(),
         }
 
 
@@ -495,16 +471,8 @@ def get_extra_context(self, request, instance):
             (Device.objects.restrict(request.user, 'view').filter(location__in=locations), 'location_id'),
         )
 
-        nonracked_devices = Device.objects.filter(
-            location=instance,
-            rack__isnull=True,
-            parent_bay__isnull=True
-        ).prefetch_related('device_type__manufacturer', 'parent_bay', 'device_role')
-
         return {
             'related_models': related_models,
-            'nonracked_devices': nonracked_devices.order_by('-pk')[:10],
-            'total_nonracked_devices_count': nonracked_devices.count(),
         }
 
 


Test patch:
Repository: netbox-community/netbox

Issue:
Add LX.5 port type
### NetBox version

v3.4.10

### Feature type

Change to existing functionality

### Proposed functionality

Add port types:

1. LX.5 PC/UPC  
2. LX.5 APC  
3. LX.5 

### Use case

Modelling optical ports with LX.5 connector type.

1. - LX.5 single mode PC/UPC
2. - LX.5 single mode APC
3. - LX.5 multimode


![image](https://github.com/netbox-community/netbox/assets/65233127/d62aa2bf-453a-4743-a78d-0a6511bcc33e)
I started with discussion but decided to open issue for enhancement.

Standards defining LX.5 connector type are IEC 61754-23 and TIA 604-13

https://github.com/netbox-community/netbox/discussions/12545

### Database changes

/

### External dependencies

/


Discussion:
I'll take this one

Resolving patch:
diff --git a/netbox/dcim/choices.py b/netbox/dcim/choices.py
--- a/netbox/dcim/choices.py
+++ b/netbox/dcim/choices.py
@@ -1223,6 +1223,10 @@ class PortTypeChoices(ChoiceSet):
     TYPE_LSH_PC = 'lsh-pc'
     TYPE_LSH_UPC = 'lsh-upc'
     TYPE_LSH_APC = 'lsh-apc'
+    TYPE_LX5 = 'lx5'
+    TYPE_LX5_PC = 'lx5-pc'
+    TYPE_LX5_UPC = 'lx5-upc'
+    TYPE_LX5_APC = 'lx5-apc'
     TYPE_SPLICE = 'splice'
     TYPE_CS = 'cs'
     TYPE_SN = 'sn'
@@ -1269,6 +1273,10 @@ class PortTypeChoices(ChoiceSet):
                 (TYPE_LSH_PC, 'LSH/PC'),
                 (TYPE_LSH_UPC, 'LSH/UPC'),
                 (TYPE_LSH_APC, 'LSH/APC'),
+                (TYPE_LX5, 'LX.5'),
+                (TYPE_LX5_PC, 'LX.5/PC'),
+                (TYPE_LX5_UPC, 'LX.5/UPC'),
+                (TYPE_LX5_APC, 'LX.5/APC'),
                 (TYPE_MPO, 'MPO'),
                 (TYPE_MTRJ, 'MTRJ'),
                 (TYPE_SC, 'SC'),


Test patch:
Repository: netbox-community/netbox

Issue:
Wrong rounding in rack-level power utilization figure
### NetBox version

v3.5.3

### Python version

3.8

### Steps to Reproduce

1. Create a power feed and some devices in a rack, such that the power utilization on the power feed is 2.5% - specific instructions in discussion #12837
2. Look at the power feed utilization
3. Look at the rack level power utilization

### Expected Behavior

Both to show the same

### Observed Behavior

Power-feed utilization shows as "2.5%"

![](https://user-images.githubusercontent.com/44789/244380583-33a6e41e-2c5a-41fa-9744-4df1e386cab3.png)

But rack-level utilization power shows as "2.0%"

![](https://user-images.githubusercontent.com/44789/244382228-41acdf97-60e4-4e2c-a3ac-802ee4809d37.png)

The problem is that percentage() in `netbox/utilities/templatetags/helpers.py` rounds to nearest 0.1%

```
return round(x / y * 100, 1)
```

Whereas Rack.get_power_utilization in netbox/dcim/models/racks.py rounds down to integer:

```
return int(allocated_draw / available_power_total * 100)
```



Discussion:

Resolving patch:
diff --git a/netbox/dcim/models/racks.py b/netbox/dcim/models/racks.py
--- a/netbox/dcim/models/racks.py
+++ b/netbox/dcim/models/racks.py
@@ -466,7 +466,7 @@ def get_power_utilization(self):
             powerport.get_power_draw()['allocated'] for powerport in powerports
         ])
 
-        return int(allocated_draw / available_power_total * 100)
+        return round(allocated_draw / available_power_total * 100, 1)
 
     @cached_property
     def total_weight(self):


Test patch:
Repository: netbox-community/netbox

Issue:
Include "add" button on navigation menu for wireless links
### NetBox version

v3.5.3

### Python version

3.8

### Steps to Reproduce

The Current view in the sidebar for the `Connections > Wireless Links` contains the `Import` button but not the `Add` button which is available in the main view.

<img width="1440" alt="Screen Shot 2023-06-11 at 12 09 42 PM" src="https://github.com/netbox-community/netbox/assets/4545925/5bd70501-a887-44c7-a69d-7ffa433bd862">

### Expected Behavior

**Expectation:** The Green Add button should be available in the sidebar for the `Wireless Links`
<img width="1440" alt="Screen Shot 2023-06-11 at 12 10 43 PM" src="https://github.com/netbox-community/netbox/assets/4545925/cc37dc18-788e-4b69-a5ab-f254fd8fdc4d">


### Observed Behavior

The sidebar does not have the Add button.


Discussion:

Resolving patch:
diff --git a/netbox/netbox/navigation/menu.py b/netbox/netbox/navigation/menu.py
--- a/netbox/netbox/navigation/menu.py
+++ b/netbox/netbox/navigation/menu.py
@@ -102,7 +102,7 @@
             label=_('Connections'),
             items=(
                 get_model_item('dcim', 'cable', _('Cables'), actions=['import']),
-                get_model_item('wireless', 'wirelesslink', _('Wireless Links'), actions=['import']),
+                get_model_item('wireless', 'wirelesslink', _('Wireless Links')),
                 MenuItem(
                     link='dcim:interface_connections_list',
                     link_text=_('Interface Connections'),


Test patch:
Repository: netbox-community/netbox

Issue:
Include "add" buttons on navigation menu for reports and scripts
### NetBox version

v3.5.3

### Python version

3.8

### Steps to Reproduce

1. Once the netbox server instance is running, login into the application with the user credentials
2. In the sidebar, uncollapse the `Customization` section and scroll to the `Reports and Scripts`
3. The quick `Add` buttons are missing for both `Reports` and `Scripts`, while their corresponding views contain `Add` buttons.

<img width="258" alt="Screen Shot 2023-06-11 at 1 15 04 PM" src="https://github.com/netbox-community/netbox/assets/4545925/e9efc5da-aa8a-424b-8b17-750e27c158ca">


### Expected Behavior

The elements for `Reports` and `Scripts` should contain the quick `Add` buttons.

### Observed Behavior

The buttons are missing.


Discussion:

Resolving patch:
diff --git a/netbox/netbox/navigation/menu.py b/netbox/netbox/navigation/menu.py
--- a/netbox/netbox/navigation/menu.py
+++ b/netbox/netbox/navigation/menu.py
@@ -301,12 +301,14 @@
                 MenuItem(
                     link='extras:report_list',
                     link_text=_('Reports'),
-                    permissions=['extras.view_report']
+                    permissions=['extras.view_report'],
+                    buttons=get_model_buttons('extras', "reportmodule", actions=['add'])
                 ),
                 MenuItem(
                     link='extras:script_list',
                     link_text=_('Scripts'),
-                    permissions=['extras.view_script']
+                    permissions=['extras.view_script'],
+                    buttons=get_model_buttons('extras', "scriptmodule", actions=['add'])
                 ),
             ),
         ),


Test patch:
Repository: netbox-community/netbox

Issue:
Clearing the ordering of a table does not clear the `ordering` key from the UserConfig data
### NetBox version

v3.5.3

### Python version

3.8

### Steps to Reproduce

1. Open the sites list and order the entries by name.
2. In a shell, retrieve the UserConfig instance for your user and inspect the entry for `tables.SiteTable.ordering`:

```
>>> uc=UserConfig.objects.get(user__username='admin')
>>> uc.data['tables']['SiteTable']['ordering']
['name']
```

3. In the UI, clear the applied ordering by clicking the X in the column header.
4. Refresh and re-inspect the UserConfig data:

```
>>> uc.refresh_from_db()
>>> uc.data['tables']['SiteTable']['ordering']
['']
```

### Expected Behavior

The `ordering` key should be removed from the data, as there is no longer any preference stored.

### Observed Behavior

`ordering` is set to a list containing an empty string. This does not effect any breaking behavior AFAICT, however it should be cleaned up as it can pose complications.


Discussion:

Resolving patch:
diff --git a/netbox/netbox/tables/tables.py b/netbox/netbox/tables/tables.py
--- a/netbox/netbox/tables/tables.py
+++ b/netbox/netbox/tables/tables.py
@@ -140,10 +140,14 @@ def configure(self, request):
         if request.user.is_authenticated:
             table_name = self.__class__.__name__
             if self.prefixed_order_by_field in request.GET:
-                # If an ordering has been specified as a query parameter, save it as the
-                # user's preferred ordering for this table.
-                ordering = request.GET.getlist(self.prefixed_order_by_field)
-                request.user.config.set(f'tables.{table_name}.ordering', ordering, commit=True)
+                if request.GET[self.prefixed_order_by_field]:
+                    # If an ordering has been specified as a query parameter, save it as the
+                    # user's preferred ordering for this table.
+                    ordering = request.GET.getlist(self.prefixed_order_by_field)
+                    request.user.config.set(f'tables.{table_name}.ordering', ordering, commit=True)
+                else:
+                    # If the ordering has been set to none (empty), clear any existing preference.
+                    request.user.config.clear(f'tables.{table_name}.ordering', commit=True)
             elif ordering := request.user.config.get(f'tables.{table_name}.ordering'):
                 # If no ordering has been specified, set the preferred ordering (if any).
                 self.order_by = ordering


Test patch: