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

Issue:
Interfaces not sorted in natural order in cable connection interface selection
### NetBox version

v3.0.2

### Python version

3.8

### Steps to Reproduce

1. Create two devices
2. On the first device, click the Connect cable button and select "Interface"
3. In the B side dialog, enter the second device name, and then select from the list of interfaces

### Expected Behavior

Interfaces to be displayed in "natural" order, i.e. the same as in the main interface listing

(In my test I was using a Netgear switch with interfaces 0/1, 0/2, ... 0/9, 0/10, 0/11, .... 0/19, 0/20, 0/21 ...)

### Observed Behavior

Interfaces are shown in "alphabetical" order, e.g. 0/19 comes before 0/2

![image](https://user-images.githubusercontent.com/44789/133431523-dda00950-7444-431a-b717-2963a519c33e.png)




Discussion:
It looks like the `<select>` options are being [automatically sorted](https://github.com/netbox-community/netbox/blob/baf045aed656b20e2fb473b2642adb9193076d0b/netbox/project-static/src/select/api/apiSelect.ts#L157) by the front end. AFAICT this should never be needed, since the REST API returns these already in order, but I could be mistaken. @thatmattlove do you know of any instances where this is needed?

Maybe we should at least invert this behavior, and sort only where we know it's necessary.

Resolving patch:
diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py
--- a/netbox/dcim/forms.py
+++ b/netbox/dcim/forms.py
@@ -2202,9 +2202,7 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
             api_url='/api/dcim/racks/{{rack}}/elevation/',
             attrs={
                 'disabled-indicator': 'device',
-                'data-query-param-face': "[\"$face\"]",
-                # The UI will not sort this element's options.
-                'pre-sorted': ''
+                'data-query-param-face': "[\"$face\"]"
             }
         )
     )


Test patch:
Repository: netbox-community/netbox

Issue:
Showing prefix of the site that has many prefixes is slow
### NetBox version

v3.0.3

### Python version

3.9

### Steps to Reproduce

1. Add a site and some prefixes under the site. (The site has 48 prefixes in our environment, and some of them have some child prefixes. One of them has over 30 child prefixes.)
2. Click site from the left menu, select the added site, click prefix on the right corner of the site page.


### Expected Behavior

The prefix page of the site shows within seconds.

### Observed Behavior

It took around 40 seconds to show 50 prefixes on a page.

Calculation of prefix utilization seems to consume a lot of execution time: after hiding the utilization bar (%) by "Configure Table," it took 1 second to show.
I'm preparing a Pull Request to optimize the utilization calculation.



Discussion:

Resolving patch:
diff --git a/netbox/ipam/models/ip.py b/netbox/ipam/models/ip.py
--- a/netbox/ipam/models/ip.py
+++ b/netbox/ipam/models/ip.py
@@ -487,11 +487,9 @@ def get_utilization(self):
             utilization = int(float(child_prefixes.size) / self.prefix.size * 100)
         else:
             # Compile an IPSet to avoid counting duplicate IPs
-            child_ips = netaddr.IPSet()
-            for iprange in self.get_child_ranges():
-                child_ips.add(iprange.range)
-            for ip in self.get_child_ips():
-                child_ips.add(ip.address.ip)
+            child_ips = netaddr.IPSet(
+                [_.range for _ in self.get_child_ranges()] + [_.address.ip for _ in self.get_child_ips()]
+            )
 
             prefix_size = self.prefix.size
             if self.prefix.version == 4 and self.prefix.prefixlen < 31 and not self.is_pool:


Test patch:
Repository: netbox-community/netbox

Issue:
Possibility to order scripts
### NetBox version

v2.11.12

### Feature type

Change to existing functionality

### Proposed functionality

As of Netbox 2.11.x, scripts are automatically discovered and rendered in the UI (extras/scripts/). The order of the scripts is based on alphabetical order.

We propose the possibility for the developer to order the scripts listing inside a python module. We'd like to propose the same implementation as was done for reports in PR #7369.

```python

MySuperScript(Script)
    pass

MySecondSuperScript(Script)
    pass

script_order = (MySuperScript, MySecondSuperScript)

```

### Use case

Adding the possibility to order scripts would allow to present some kind of script's workflow within a specific module easily.

### Database changes

_No response_

### External dependencies

_No response_


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
@@ -470,7 +470,6 @@ def get_scripts(use_names=False):
     defined name in place of the actual module name.
     """
     scripts = OrderedDict()
-
     # Iterate through all modules within the reports path. These are the user-created files in which reports are
     # defined.
     for importer, module_name, _ in pkgutil.iter_modules([settings.SCRIPTS_ROOT]):
@@ -478,11 +477,14 @@ def get_scripts(use_names=False):
         if use_names and hasattr(module, 'name'):
             module_name = module.name
         module_scripts = OrderedDict()
-        for name, cls in inspect.getmembers(module, is_script):
-            module_scripts[name] = cls
+        script_order = getattr(module, "script_order", ())
+        ordered_scripts = [cls for cls in script_order if is_script(cls)]
+        unordered_scripts = [cls for _, cls in inspect.getmembers(module, is_script) if cls not in script_order]
+        for cls in [*ordered_scripts, *unordered_scripts]:
+            module_scripts[cls.__name__] = cls
         if module_scripts:
             scripts[module_name] = module_scripts
-
+    
     return scripts
 
 


Test patch:
Repository: netbox-community/netbox

Issue:
NewVersion showing url
### NetBox version

v3.0.7

### Python version

3.7

### Steps to Reproduce

When a new release is available, Netbox wil inform the admins about it.

Fix : 
https://github.com/netbox-community/netbox/blob/1f4263aa6d7c4f054f1ccd6fd2249f8314dfa3c7/netbox/netbox/views/__init__.py#L140
replace that with
'version': str(release_verion),

### Expected Behavior

A nice view with the new version number, with an hyperlink to the release on github 
![good](https://user-images.githubusercontent.com/74899468/137447665-15be7a52-ed5c-441d-948e-c849ee3496ea.png)

### Observed Behavior

The version is shown with the url, but containing the git url as text, rather than an hyperlink
![bad](https://user-images.githubusercontent.com/74899468/137447560-09d445fb-ef1d-4065-8cfc-9bbfa65678a7.png)



Discussion:
If I use following regex:
import re
re.search("([0-9].[0-9].[0-9])", str(latest_release)).string

Could it help to solve?

Regards,

Aldo Pellini

Resolving patch:
diff --git a/netbox/netbox/views/__init__.py b/netbox/netbox/views/__init__.py
--- a/netbox/netbox/views/__init__.py
+++ b/netbox/netbox/views/__init__.py
@@ -137,7 +137,7 @@ def build_stats():
                 release_version, release_url = latest_release
                 if release_version > version.parse(settings.VERSION):
                     new_release = {
-                        'version': str(latest_release),
+                        'version': str(release_version),
                         'url': release_url,
                     }
 


Test patch:
Repository: netbox-community/netbox

Issue:
Missing tags in available column selection from IP range table
### NetBox version

v3.0.8

### Python version

3.8

### Steps to Reproduce

1. Create ip-range with tag
2. open ip-range table
3. click configure table
4. tags is missing from available column seletion
<img width="798" alt="No tags in column selection" src="https://user-images.githubusercontent.com/60612073/139842341-d7542425-22c6-4418-a190-3f4af90a177c.png">



### Expected Behavior

tag column can be selected under available columns

### Observed Behavior

tag column is missing 


Discussion:
Looks like `'tags'` is missing from `IPRangeTable.Meta.fields`.

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
@@ -269,7 +269,7 @@ class Meta(BaseTable.Meta):
         model = IPRange
         fields = (
             'pk', 'start_address', 'end_address', 'size', 'vrf', 'status', 'role', 'tenant', 'description',
-            'utilization',
+            'utilization','tags',
         )
         default_columns = (
             'pk', 'start_address', 'end_address', 'size', 'vrf', 'status', 'role', 'tenant', 'description',


Test patch:
Repository: netbox-community/netbox

Issue:
Device table not sortable by status
### NetBox version

v3.0.9

### Python version

3.8

### Steps to Reproduce

1. Click on sidebar `Devices` -> `Device Bays`
2. On the displayed table's header click on `Status`

### Expected Behavior

Table is displayed reordered, by status

### Observed Behavior

Server Error


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
@@ -653,7 +653,8 @@ class DeviceBayTable(DeviceComponentTable):
         }
     )
     status = tables.TemplateColumn(
-        template_code=DEVICEBAY_STATUS
+        template_code=DEVICEBAY_STATUS,
+        order_by=Accessor('installed_device__status')
     )
     installed_device = tables.Column(
         linkify=True


Test patch:
Repository: netbox-community/netbox

Issue:
Improve hot-reloading of custom scripts
### NetBox version

V3.0.9

### Feature type

Change to existing functionality

### Proposed functionality

Allow renaming of classes in custom scripts. Currently if you rename a class or remove a class from a file, netbox will throw `OSError : could not find class definition` and the script functionality will be broken until the application server is restarted.

The reason for this is that python uses sys.modules to cache all imported modules. When you change a class in the script and reload it in get_scripts, which is called on both the list view and when executing scripts, the module includes both the old name for the class and the new name (not sure why), causing the import to fail on the old name.

The solution is pretty simple, deleting the module from sys.modules. A simple implementation can be seen here:

https://github.com/kkthxbye-code/netbox/commit/ae6ed97a80f55e87cd75dc0e942069758a1cd38d

I wasn't able to notice any performance regressions, the extra load should be minimal even with a lot of scripts. The advantage is that the loaded script is actually correct.

### Use case

Scripts already allow changing code without restart, with the requested change you will also be able to rename or delete script classes.

### Database changes

None

### External dependencies

None


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
@@ -3,6 +3,7 @@
 import logging
 import os
 import pkgutil
+import sys
 import traceback
 from collections import OrderedDict
 
@@ -477,6 +478,10 @@ def get_scripts(use_names=False):
     # Iterate through all modules within the reports path. These are the user-created files in which reports are
     # defined.
     for importer, module_name, _ in pkgutil.iter_modules([settings.SCRIPTS_ROOT]):
+        # Remove cached module to ensure consistency with filesystem
+        if module_name in sys.modules:
+            del sys.modules[module_name]
+
         module = importer.find_module(module_name).load_module(module_name)
         if use_names and hasattr(module, 'name'):
             module_name = module.name


Test patch:
Repository: netbox-community/netbox

Issue:
VLAN Group information in the Prefixes overview would help
### NetBox version

v3.0.7

### Feature type

Change to existing functionality

### Proposed functionality

Extend the VLAN information on the Prefixes overview by also showing the VLAN Group information.

### Use case

VLANs can exist multiple times in an IPAM, and the distinguisher is the VLAN Group.
While in an individual Prefixes view the VLAN shows both the VLAN Group and the VLAN information, separated by a slash, in the Prefixes overview the VLAN column only shows the VLAN.
A similar display of VLAN Group/VLAN like in the individual Prefix would greatly improve the overview.

### Database changes

none

### External dependencies

_No response_


Discussion:
I support that - would be helpful for export and import prefixes
As vlan groups are not displayed in exports, those can't be used as import templates without adding those
I wonder whether this is looked into, as it is much more than just the "display".
As elwonk mentioned, the vlan group is not even exported which makes a reimport/migration of existing data impossible.
Sounds like just adding a column for VLAN group to the prefix table (as a non-default column) would address this.

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
@@ -206,6 +206,11 @@ class PrefixTable(BaseTable):
     site = tables.Column(
         linkify=True
     )
+    vlan_group = tables.Column(
+        accessor='vlan__group',
+        linkify=True,
+        verbose_name='VLAN Group'
+    )
     vlan = tables.Column(
         linkify=True,
         verbose_name='VLAN'
@@ -230,8 +235,8 @@ class PrefixTable(BaseTable):
     class Meta(BaseTable.Meta):
         model = Prefix
         fields = (
-            'pk', 'id', 'prefix', 'prefix_flat', 'status', 'children', 'vrf', 'utilization', 'tenant', 'site', 'vlan', 'role',
-            'is_pool', 'mark_utilized', 'description', 'tags',
+            'pk', 'id', 'prefix', 'prefix_flat', 'status', 'children', 'vrf', 'utilization', 'tenant', 'site', 'vlan_group',
+            'vlan', 'role', 'is_pool', 'mark_utilized', 'description', 'tags',
         )
         default_columns = (
             'pk', 'prefix', 'status', 'children', 'vrf', 'utilization', 'tenant', 'site', 'vlan', 'role', 'description',


Test patch:
Repository: netbox-community/netbox

Issue:
CEE 7/5 exists as power port and power outlet. It is only a power port.
### NetBox version

v3.0.10

### Python version

3.7

### Steps to Reproduce

1. Add a power port to a device type.
2. Try to select CEE 7/6 plug (French; Type E).

### Expected Behavior

"ITA Type E (CEE 7/6)" is available.

### Observed Behavior

"ITA Type E (CEE 7/5)" is available.

### Refs

* https://en.wikipedia.org/wiki/CEE_7_standard_AC_plugs_and_sockets#CEE_7/5_socket_and_CEE_7/6_plug_(French;_Type_E)
* https://blog.packetsar.com/wp-content/uploads/Power_and_Cooling_Cheat_Sheet.pdf
* #792
* https://github.com/netbox-community/netbox/commit/dd3e7397a421032c2c9b92fce478402323e00b34


Discussion:

Resolving patch:
diff --git a/netbox/dcim/choices.py b/netbox/dcim/choices.py
--- a/netbox/dcim/choices.py
+++ b/netbox/dcim/choices.py
@@ -428,7 +428,7 @@ class PowerPortTypeChoices(ChoiceSet):
         )),
         ('International/ITA', (
             (TYPE_ITA_C, 'ITA Type C (CEE 7/16)'),
-            (TYPE_ITA_E, 'ITA Type E (CEE 7/5)'),
+            (TYPE_ITA_E, 'ITA Type E (CEE 7/6)'),
             (TYPE_ITA_F, 'ITA Type F (CEE 7/4)'),
             (TYPE_ITA_EF, 'ITA Type E/F (CEE 7/7)'),
             (TYPE_ITA_G, 'ITA Type G (BS 1363)'),
@@ -640,8 +640,8 @@ class PowerOutletTypeChoices(ChoiceSet):
             (TYPE_CS8464C, 'CS8464C'),
         )),
         ('ITA/International', (
-            (TYPE_ITA_E, 'ITA Type E (CEE7/5)'),
-            (TYPE_ITA_F, 'ITA Type F (CEE7/3)'),
+            (TYPE_ITA_E, 'ITA Type E (CEE 7/5)'),
+            (TYPE_ITA_F, 'ITA Type F (CEE 7/3)'),
             (TYPE_ITA_G, 'ITA Type G (BS 1363)'),
             (TYPE_ITA_H, 'ITA Type H'),
             (TYPE_ITA_I, 'ITA Type I'),


Test patch:
Repository: netbox-community/netbox

Issue:
L22-30P power port type
### NetBox version

v3.0.7

### Feature type

Data model extension

### Proposed functionality

Under power port type, L22-30P is missing. Adding it as an option would be great.

### Use case

Allow for proper documentation as it is a common locking plug type

### Database changes

_No response_

### External dependencies

_No response_


Discussion:

Resolving patch:
diff --git a/netbox/dcim/choices.py b/netbox/dcim/choices.py
--- a/netbox/dcim/choices.py
+++ b/netbox/dcim/choices.py
@@ -312,6 +312,7 @@ class PowerPortTypeChoices(ChoiceSet):
     TYPE_NEMA_L1560P = 'nema-l15-60p'
     TYPE_NEMA_L2120P = 'nema-l21-20p'
     TYPE_NEMA_L2130P = 'nema-l21-30p'
+    TYPE_NEMA_L2230P = 'nema-l22-30p'
     # California style
     TYPE_CS6361C = 'cs6361c'
     TYPE_CS6365C = 'cs6365c'
@@ -417,6 +418,7 @@ class PowerPortTypeChoices(ChoiceSet):
             (TYPE_NEMA_L1560P, 'NEMA L15-60P'),
             (TYPE_NEMA_L2120P, 'NEMA L21-20P'),
             (TYPE_NEMA_L2130P, 'NEMA L21-30P'),
+            (TYPE_NEMA_L2230P, 'NEMA L22-30P'),
         )),
         ('California Style', (
             (TYPE_CS6361C, 'CS6361C'),
@@ -533,6 +535,7 @@ class PowerOutletTypeChoices(ChoiceSet):
     TYPE_NEMA_L1560R = 'nema-l15-60r'
     TYPE_NEMA_L2120R = 'nema-l21-20r'
     TYPE_NEMA_L2130R = 'nema-l21-30r'
+    TYPE_NEMA_L2230R = 'nema-l22-30r'
     # California style
     TYPE_CS6360C = 'CS6360C'
     TYPE_CS6364C = 'CS6364C'
@@ -630,6 +633,7 @@ class PowerOutletTypeChoices(ChoiceSet):
             (TYPE_NEMA_L1560R, 'NEMA L15-60R'),
             (TYPE_NEMA_L2120R, 'NEMA L21-20R'),
             (TYPE_NEMA_L2130R, 'NEMA L21-30R'),
+            (TYPE_NEMA_L2230R, 'NEMA L22-30R'),
         )),
         ('California Style', (
             (TYPE_CS6360C, 'CS6360C'),


Test patch:
Repository: netbox-community/netbox

Issue:
Linkify VLAN name in VLAN tables
### NetBox version

v3.0.11-dev

### Feature type

New functionality

### Proposed functionality

Make the VLAN name in the VLANs list view and the  VLAN Group > VLANs table clickable to access the VLAN detail page.

I believe this is simply a matter of adding the following snippet to `VLANTable` in `netbox/ipam/tables/vlans.py`
```
    name = tables.Column(
        linkify=True
    )
```

### Use case

Currently, only the VLAN ID is clickable. This can be a decently small target for the mouse cursor. By making the VLAN name clickable as well, it's easier to click through to a specific VLAN. 

### Database changes

_No response_

### External dependencies

_No response_


Discussion:

Resolving patch:
diff --git a/netbox/ipam/tables/vlans.py b/netbox/ipam/tables/vlans.py
--- a/netbox/ipam/tables/vlans.py
+++ b/netbox/ipam/tables/vlans.py
@@ -95,6 +95,9 @@ class VLANTable(BaseTable):
         template_code=VLAN_LINK,
         verbose_name='VID'
     )
+    name = tables.Column(
+        linkify=True
+    )
     site = tables.Column(
         linkify=True
     )


Test patch:
Repository: netbox-community/netbox

Issue:
Markdown tables missing CSS style
### NetBox version

v3.0.8

### Python version

3.8

### Steps to Reproduce

1. after upgrading to v3.0, a plugin that I wrote before which has render_markdown in its HTML page can not work properly. I would want to render a table by inputting
![Screenshot from 2021-12-17 18-03-18](https://user-images.githubusercontent.com/88376287/146527117-ea173686-e0c1-452c-8480-79feb6db31d0.png)
but what I get is not a table
2. I tried this input in some other places using `render_mardown` like Circuits.providers.comments, they showed the same result:
![Screenshot from 2021-12-17 18-00-17](https://user-images.githubusercontent.com/88376287/146526685-488ecc32-e41d-453f-8b2a-aeb8f360e8d0.png)


### Expected Behavior

a table would show up

### Observed Behavior

no table show up


Discussion:
The table is there:

![image](https://user-images.githubusercontent.com/400797/146527934-e02bf595-de2d-43e1-bead-dc76ac97bd9e.png)

I'm guessing your issue is that it is un-styled.

Adding class="table" to the table element turns it into this:

![image](https://user-images.githubusercontent.com/400797/146528433-c762cdc5-3171-4f15-977c-c54095c7c624.png)

Is that what you expected?

Not sure how to fix it in a non-ugly way. Either define custom css for tables with no class or extend the table extension in python-markdown.
> The table is there:
> 
> ![image](https://user-images.githubusercontent.com/400797/146527934-e02bf595-de2d-43e1-bead-dc76ac97bd9e.png)
> 
> I'm guessing your issue is that it is un-styled.
> 
> Adding class="table" to the table element turns it into this:
> 
> ![image](https://user-images.githubusercontent.com/400797/146528433-c762cdc5-3171-4f15-977c-c54095c7c624.png)
> 
> Is that what you expected?
> 
> Not sure how to fix it in a non-ugly way. Either define custom css for tables with no class or extend the table extension in python-markdown.



thanks, but why can you have so much space in each column? Mine looks much more ugly than yours. How and where did you ad class="table"?

![Screenshot from 2021-12-20 13-20-16](https://user-images.githubusercontent.com/88376287/146715610-d7866d0e-55a0-4648-8fb5-9e0198f6c120.png) @kkthxbye-code 
I can take this one @jeremystretch 

You fixed it here before:

https://github.com/netbox-community/netbox/commit/2fce7ebd8fee511a0fef8b3aada11037e8ef8e9f

The CSS was just not ported to v3.0.
@kkthxbye-code thanks!

Resolving patch:
diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py
--- a/netbox/utilities/templatetags/helpers.py
+++ b/netbox/utilities/templatetags/helpers.py
@@ -59,6 +59,10 @@ def render_markdown(value):
     # Render Markdown
     html = markdown(value, extensions=['fenced_code', 'tables', StrikethroughExtension()])
 
+    # If the string is not empty wrap it in rendered-markdown to style tables
+    if html:
+        html = f'<div class="rendered-markdown">{html}</div>'
+
     return mark_safe(html)
 
 


Test patch: