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

Issue:
IP-addresses created via addition of FHRP group do not inherit default custom field values
### NetBox version

3.1.10

### Python version

3.9

### Steps to Reproduce

1. Create a boolean custom field with a certain default value, for example **False**, and assign it the `ipam | IP address`-model.
2. Add a new FHRP group (IPAM -> FHRP Groups) with a new, unused IP-address under **Virtual IP Address**.
3. The new IP-address object attached to the VHRP-group does not have the custom field set, which generates an error when running reports.

### Expected Behavior

I'd expect the new IP-address to have the default custom field value.

### Observed Behavior

An exception occurred: KeyError: 'my_custom_field' Traceback (most recent call last): File "/usr/lib/netbox/app/extras/reports.py", line 234, in run test_method() File "/usr/local/lib/netbox/reports/my_report.py", line 11, in test_for_field if ip.custom_field_data["my_custom_field"]: 'my_custom_field'


Discussion:
Related to #11040

Resolving patch:
diff --git a/netbox/ipam/forms/model_forms.py b/netbox/ipam/forms/model_forms.py
--- a/netbox/ipam/forms/model_forms.py
+++ b/netbox/ipam/forms/model_forms.py
@@ -578,6 +578,7 @@ def save(self, *args, **kwargs):
                 role=FHRP_PROTOCOL_ROLE_MAPPINGS.get(self.cleaned_data['protocol'], IPAddressRoleChoices.ROLE_VIP),
                 assigned_object=instance
             )
+            ipaddress.populate_custom_field_defaults()
             ipaddress.save()
 
             # Check that the new IPAddress conforms with any assigned object-level permissions
diff --git a/netbox/netbox/models/features.py b/netbox/netbox/models/features.py
--- a/netbox/netbox/models/features.py
+++ b/netbox/netbox/models/features.py
@@ -216,6 +216,13 @@ def get_custom_fields_by_group(self):
 
         return dict(groups)
 
+    def populate_custom_field_defaults(self):
+        """
+        Apply the default value for each custom field
+        """
+        for cf in self.custom_fields:
+            self.custom_field_data[cf.name] = cf.default
+
     def clean(self):
         super().clean()
         from extras.models import CustomField


Test patch:
Repository: netbox-community/netbox

Issue:
Expose FILE_UPLOAD_MAX_MEMORY_SIZE as a setting in core netbox
### NetBox version

v3.3.9

### Feature type

New functionality

### Proposed functionality

Raised [this issue](https://github.com/netbox-community/netbox-docker/issues/897) to investigate it and was advised that FILE_UPLOAD_MAX_MEMORY_SIZE setting is not configurable, hence need to raise a request to add it to core Netbox functionality.

### Use case

To be able to upload files bigger than 2.5Mbyte to custom scripts for processing.

### Database changes

Nill

### External dependencies

Nill


Discussion:
I volunteer to own this. 

Resolving patch:
diff --git a/netbox/netbox/configuration_example.py b/netbox/netbox/configuration_example.py
--- a/netbox/netbox/configuration_example.py
+++ b/netbox/netbox/configuration_example.py
@@ -217,6 +217,10 @@
 # this setting is derived from the installed location.
 # SCRIPTS_ROOT = '/opt/netbox/netbox/scripts'
 
+# The maximum size (in bytes) that an upload will be before it gets streamed to the file system.
+# Useful to be able to upload files bigger than 2.5Mbyte to custom scripts for processing.
+# FILE_UPLOAD_MAX_MEMORY_SIZE = 2621440
+
 # The name to use for the csrf token cookie.
 CSRF_COOKIE_NAME = 'csrftoken'
 
diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py
--- a/netbox/netbox/settings.py
+++ b/netbox/netbox/settings.py
@@ -91,6 +91,7 @@
 EMAIL = getattr(configuration, 'EMAIL', {})
 EXEMPT_VIEW_PERMISSIONS = getattr(configuration, 'EXEMPT_VIEW_PERMISSIONS', [])
 FIELD_CHOICES = getattr(configuration, 'FIELD_CHOICES', {})
+FILE_UPLOAD_MAX_MEMORY_SIZE = getattr(configuration, 'FILE_UPLOAD_MAX_MEMORY_SIZE', 2621440)
 HTTP_PROXIES = getattr(configuration, 'HTTP_PROXIES', None)
 INTERNAL_IPS = getattr(configuration, 'INTERNAL_IPS', ('127.0.0.1', '::1'))
 JINJA2_FILTERS = getattr(configuration, 'JINJA2_FILTERS', {})


Test patch:
Repository: netbox-community/netbox

Issue:
GraphQL returns all objects if tag doesn't exist
### NetBox version

v3.4.2

### Python version

3.10

### Steps to Reproduce

1. query GraphQL for device/interface with a tag that doesn't exist

### Expected Behavior

Resulting list of devices/interfaces only contains devices matching the tags or none if no device exists with matching tags.

### Observed Behavior

All devices/interfaces are returned no matter what tag filter has been applied. Same seems to apply for all kinds of filters that can be defined in GraphQL. No errors are returned.

Example below

query:
`{
  device_list(tag: "blablalba") {
    id
    name
    tags {
      name
    }
  }
    interface_list(tag: "not-ipmi_exporter") {
    id
    device {
      id
    }
     tags {
      name
    }
  }
}
`

result:
`{
  "data": {
    "device_list": [
      {
        "id": "1",
        "name": "device-A",
        "tags": [
          {
            "name": "node_exporter"
          }
        ]
      },
      {
        "id": "2",
        "name": "device-B",
        "tags": [
          {
            "name": "node_exporter"
          }
        ]
      }
    ],
    "interface_list": [
      {
        "id": "1",
        "device": {
          "id": "1"
        },
        "tags": [
          {
            "name": "ipmi_exporter"
          }
        ]
      },
      {
        "id": "2",
        "device": {
          "id": "2"
        },
        "tags": [
          {
            "name": "ipmi_exporter"
          }
        ]
      }
    ]
  }
}`


Discussion:
I think this could be solved by checking if the filterset is valid in ObjectListField.list_resolver() static method and returning an empty queryset if not valid.

I can take a look at this.

Resolving patch:
diff --git a/netbox/netbox/graphql/fields.py b/netbox/netbox/graphql/fields.py
--- a/netbox/netbox/graphql/fields.py
+++ b/netbox/netbox/graphql/fields.py
@@ -60,6 +60,8 @@ def list_resolver(django_object_type, resolver, default_manager, root, info, **a
         filterset_class = django_object_type._meta.filterset_class
         if filterset_class:
             filterset = filterset_class(data=args, queryset=queryset, request=info.context)
+            if not filterset.is_valid():
+                return queryset.none()
             return filterset.qs
 
         return queryset


Test patch:
Repository: netbox-community/netbox

Issue:
Show rack-list dropdown in rack view
### NetBox version

v3.3.8

### Feature type

Change to existing functionality

### Proposed functionality

When viewing a rack, you have the 'previous' and 'next' button.
![image](https://user-images.githubusercontent.com/74899468/202899042-3d989f36-d4d4-4020-a673-d0d1e903b3e3.png)

Add a 'dropdown' between those 2 buttons, so that all racks of a location (or site if no location is set) are selectable
![image](https://user-images.githubusercontent.com/74899468/202899269-f6008738-18b1-4c67-9a41-047b382d940a.png)


### Use case

This will provide a faster navigation between the racks.
Another option, is to display all racks in a full-width bar with horizontal scrolling
![image](https://user-images.githubusercontent.com/74899468/202899501-162233a8-2f40-486e-b9eb-b632ea56455a.png)


### Database changes

_No response_

### External dependencies

_No response_


Discussion:
I also like this idea. Racktables had a left and right button when viewing a rack to quickly move between racks in a row. It was useful if for getting to the rack ether side of current rack in a single click
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).

Resolving patch:
diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py
--- a/netbox/dcim/views.py
+++ b/netbox/dcim/views.py
@@ -738,6 +738,7 @@ def get_extra_context(self, request, instance):
             'next_rack': next_rack,
             'prev_rack': prev_rack,
             'svg_extra': svg_extra,
+            'peer_racks': peer_racks,
         }
 
 


Test patch:
Repository: netbox-community/netbox

Issue:
Creating devices takes an inordinate amount of time
### NetBox version

v3.4.4

### Python version

3.10

### Steps to Reproduce

This issue will be used to collect what I find while investigating the issue, as such the scenario is based on my test database and test devicetype.

1. Create a devicetype with 62 interfaces
2. Create a device based on the interface
3. Notice the responsetime

### Expected Behavior

The device should be create within a reasonable time period.

### Observed Behavior

The device takes many seconds to create.

Do note, that while the performance was never great, it was made worse by both the search indexing and the fact that we fixed a bug where changelog entries were not created for instantiated components.


Discussion:

Resolving patch:
diff --git a/netbox/netbox/search/backends.py b/netbox/netbox/search/backends.py
--- a/netbox/netbox/search/backends.py
+++ b/netbox/netbox/search/backends.py
@@ -52,11 +52,11 @@ def search(self, value, user=None, object_types=None, lookup=DEFAULT_LOOKUP_TYPE
         """
         raise NotImplementedError
 
-    def caching_handler(self, sender, instance, **kwargs):
+    def caching_handler(self, sender, instance, created, **kwargs):
         """
         Receiver for the post_save signal, responsible for caching object creation/changes.
         """
-        self.cache(instance)
+        self.cache(instance, remove_existing=not created)
 
     def removal_handler(self, sender, instance, **kwargs):
         """


Test patch:
Repository: netbox-community/netbox

Issue:
Add the ability to hide virtual interfaces
### NetBox version

v3.3.5

### Feature type

New functionality

### Proposed functionality

Expand on https://github.com/netbox-community/netbox/issues/4247 to add the option to hide virtual interfaces.

Currently there are two options: Hide Enabled and Hide Disabled. I propose a third option of Hide Virtual. 
On button toggle, every interface in InterfaceTable of type "Virtual" should be hidden or shown based on the current state.

Files needing updated:
[netbox/project-static/src/tables/interfaceTable.ts](https://github.com/netbox-community/netbox/commit/e004f872f9b6c5ba1c4ad792b8b10adfc3659c7e#diff-783f2e6ec565238f5d454ad36dc74eb8efb43032bdfbbc7034fc62682c96224b)

[netbox/templates/dcim/device/interfaces.html](https://github.com/netbox-community/netbox/commit/e004f872f9b6c5ba1c4ad792b8b10adfc3659c7e#diff-735e4e23856b0bf848f6d54a14ca359dfc21eda805d680a468842b2f59fc0397)


### Use case

In my network, many of my locations have a Juniper MX204 providing PE services to that region. The MX204 only has 4x100G and 8x10G, however, we may have hundreds or thousands of sub interfaces based on how many circuits we sell. In the interfaces tab of a device, this becomes pretty cumbersome to navigate.

### Database changes

None.

### External dependencies

None.


Discussion:
I can own this

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
@@ -588,6 +588,7 @@ class Meta(DeviceComponentTable.Meta):
             'class': get_interface_row_class,
             'data-name': lambda record: record.name,
             'data-enabled': get_interface_state_attribute,
+            'data-type': lambda record: record.type,
         }
 
 


Test patch:
Repository: netbox-community/netbox

Issue:
Plugin menu label consisting of url unsafe characters breaks unfolding menu
### NetBox version

v3.4.4

### Python version

3.10

### Steps to Reproduce

Create a plugin menu with any url unsafe character (eg. { } / \ # < > ~ | ^) in its label:
```
menu = PluginMenu(
    label='menu with /slash',
    groups=(
        ('menu item', [menu_item]),
    ),
    icon_class='mdi mdi-format-list-text'
)
```
After restarting NetBox, open the GUI at the main menu
Click on the plugin menu name

### Expected Behavior

The plugin menu opens, showing the menu items.

### Observed Behavior

The plugin menu is displayed in the side bar, but does not unfold when clicking on it.

This issue is the same as https://github.com/netbox-community/netbox/issues/10984, only with url unsafe characters instead of spaces, eg ` { } / \ # < > ~ | ^`



Discussion:
Please update the steps to reproduce as they are from the referenced issue. Unless you are implying that https://github.com/netbox-community/netbox/commit/150cb772fe519404857f48e894737f0570c4bc56 did not fix it.

> Create a plugin menu with more than two words, separated by a blank, as its label:

Thanks,
sorry, copy paste fail. I've updated it now.
> sorry, copy paste fail. I've updated it now.

Thanks 😄 
I think we need to modify the PluginMenu class, in the return of the def name (netbox/extras/plugins/navigation.py). Now it only replaces the blank spaces, and if we change to rename all the special chars (prohibited in the html element names) things will work again.

If you want I can try to fix it.


Resolving patch:
diff --git a/netbox/extras/plugins/navigation.py b/netbox/extras/plugins/navigation.py
--- a/netbox/extras/plugins/navigation.py
+++ b/netbox/extras/plugins/navigation.py
@@ -1,5 +1,6 @@
 from netbox.navigation import MenuGroup
 from utilities.choices import ButtonColorChoices
+from django.utils.text import slugify
 
 __all__ = (
     'PluginMenu',
@@ -21,7 +22,7 @@ def __init__(self, label, groups, icon_class=None):
 
     @property
     def name(self):
-        return self.label.replace(' ', '_')
+        return slugify(self.label)
 
 
 class PluginMenuItem:


Test patch:
Repository: netbox-community/netbox

Issue:
Remove whitespace on header columns for CSV import
### NetBox version

v3.4.5

### Feature type

New functionality

### Proposed functionality

When performing a CSV import, whitespace on the column headers will cause that field to not import.  I propose the trimming of whitespace on each of the column headers.

### Use case

This avoids the chances of inadvertent missing data on import, which can happen for users particularly when exporting direct from spreadsheet applications and importing directly into NetBox and not carefully checking the header does not contain erroneous whitespace first in a text editor.

### Database changes

Nil.

### External dependencies

Nil.


Discussion:

Resolving patch:
diff --git a/netbox/utilities/forms/utils.py b/netbox/utilities/forms/utils.py
--- a/netbox/utilities/forms/utils.py
+++ b/netbox/utilities/forms/utils.py
@@ -195,6 +195,7 @@ def parse_csv(reader):
     # `site.slug` header, to indicate the related site is being referenced by its slug.
 
     for header in next(reader):
+        header = header.strip()
         if '.' in header:
             field, to_field = header.split('.', 1)
             headers[field] = to_field


Test patch:
Repository: netbox-community/netbox

Issue:
Export Saved Filter does not include parameters
### NetBox version

v3.4.5

### Python version

3.10

### Steps to Reproduce

1. Browse to /extras/saved-filters with at least one saved filter defined
2. Export saved filters to CSV via "Export" > "All Data (CSV)"
3. Observe that the CSV does not contain the "parameters" field which is the core data to define/import/clone a saved filter

### Expected Behavior

We would expect that the data export contains the "parameters" JSON, as this is the core value of the saved filter (all other fields are effectively metadata/housekeeping)

### Observed Behavior

The parameters of the saved filter are not present in the export, meaning their subsequent import into NetBox would be incomplete.  Parameters is a required field for import, we would expect it to be present in the export.


Discussion:
With a little bit of pointers towards the right part of the code base, I'm happy to open a PR for this.

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
@@ -1,3 +1,5 @@
+import json
+
 import django_tables2 as tables
 from django.conf import settings
 from django.utils.translation import gettext as _
@@ -110,11 +112,14 @@ class SavedFilterTable(NetBoxTable):
     enabled = columns.BooleanColumn()
     shared = columns.BooleanColumn()
 
+    def value_parameters(self, value):
+        return json.dumps(value)
+
     class Meta(NetBoxTable.Meta):
         model = SavedFilter
         fields = (
             'pk', 'id', 'name', 'slug', 'content_types', 'description', 'user', 'weight', 'enabled', 'shared',
-            'created', 'last_updated',
+            'created', 'last_updated', 'parameters'
         )
         default_columns = (
             'pk', 'name', 'content_types', 'user', 'description', 'enabled', 'shared',


Test patch:
Repository: netbox-community/netbox

Issue:
Use SSID as the display value of wireless links if set
### NetBox version

v3.4.6

### Feature type

Change to existing functionality

### Proposed functionality

Display the SSID instead of the pk when displaying wireless links. This would replicate the function of the label on cables.

Currently it looks like this:
![image](https://user-images.githubusercontent.com/400797/224949065-f279e81c-cbce-4a68-bcc4-9e08c9e1716d.png)

Where this FR suggests displaying it like so if a SSID is set:
![image](https://user-images.githubusercontent.com/400797/224949304-b7a7f11a-851f-4663-b407-91673f88b8d6.png)

The same change would be made to the title of the wireless display object details view.

### Use case

It's very rarely useful to have an object displayed by it's PK. Displaying the SSID instead would make it easier to get an idea of what wireless link is used.

If accepted I'll implement it.

### Database changes

None

### External dependencies

None


Discussion:

Resolving patch:
diff --git a/netbox/wireless/models.py b/netbox/wireless/models.py
--- a/netbox/wireless/models.py
+++ b/netbox/wireless/models.py
@@ -190,7 +190,7 @@ class Meta:
         )
 
     def __str__(self):
-        return f'#{self.pk}'
+        return self.ssid or f'#{self.pk}'
 
     def get_absolute_url(self):
         return reverse('wireless:wirelesslink', args=[self.pk])


Test patch:
Repository: netbox-community/netbox

Issue:
DataSource logs wrong count for deleted Datafiles in sync
### NetBox version

v3.5-beta1

### Python version

3.10

### Steps to Reproduce

-

### Expected Behavior

Log contains count for deleted files

### Observed Behavior

Count for updated files is logged twice



Discussion:

Resolving patch:
diff --git a/netbox/core/models/data.py b/netbox/core/models/data.py
--- a/netbox/core/models/data.py
+++ b/netbox/core/models/data.py
@@ -176,7 +176,7 @@ def sync(self):
 
             # Bulk delete deleted files
             deleted_count, _ = DataFile.objects.filter(pk__in=deleted_file_ids).delete()
-            logger.debug(f"Deleted {updated_count} files")
+            logger.debug(f"Deleted {deleted_count} files")
 
             # Walk the local replication to find new files
             new_paths = self._walk(local_path) - known_paths


Test patch:
Repository: netbox-community/netbox

Issue:
3.5-beta1: S3Backend missing from __all__
### Proposed Changes

Add `S3Backend` to `__all__` in `data_backends.py`

### Justification

All other backends are in the list.


Discussion:

Resolving patch:
diff --git a/netbox/core/data_backends.py b/netbox/core/data_backends.py
--- a/netbox/core/data_backends.py
+++ b/netbox/core/data_backends.py
@@ -20,6 +20,7 @@
 __all__ = (
     'LocalBackend',
     'GitBackend',
+    'S3Backend',
 )
 
 logger = logging.getLogger('netbox.data_backends')


Test patch:
Repository: netbox-community/netbox

Issue:
Error when creating device from device type with parent inventory item
### NetBox version

v3.4.7

### Python version

3.10

### Steps to Reproduce

1. Create a new Device Types
2. Add 1st Component :  Inventory Item
3. Add 2nd Component : Inventory Item, with 1st component as Parent
4. Create a new Device from this Device type

### Expected Behavior

New device created with Inventory Items from Device Type

### Observed Behavior

Server error : 

```
<class 'dcim.models.device_components.InventoryItem.DoesNotExist'>

InventoryItem matching query does not exist.

Python version: 3.10.6
NetBox version: 3.4.7
```


with debug : 


```
DoesNotExist at /dcim/devices/add/
InventoryItem matching query does not exist.

Request Method:  POST
Django Version: 4.1.7
Exception Type: DoesNotExist
Exception Value: InventoryItem matching query does not exist.
Exception Location: /opt/netbox/venv/lib/python3.10/site-packages/django/db/models/query.py, line 650, in get
Raised during: dcim.views.DeviceEditView
Python Executable: /opt/netbox/venv/bin/python
Python Version: 3.10.6
Python Path : ['/opt/netbox/netbox/',  '/usr/lib/python310.zip',  '/usr/lib/python3.10',  '/usr/lib/python3.10/lib-dynload',  '/opt/netbox/venv/lib/python3.10/site-packages']
```


Discussion:
This needs some logic like I created here in 3.5 for interface bridges:

https://github.com/netbox-community/netbox/pull/11869/files#diff-242fa4d6e937ebcf01bba9f882cf4f17a40799ef33b5637a00726fbfbaec7c1fR463-R476

Resolving patch:
diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py
--- a/netbox/dcim/models/devices.py
+++ b/netbox/dcim/models/devices.py
@@ -774,8 +774,10 @@ def _instantiate_components(self, queryset, bulk_create=True):
             bulk_create: If True, bulk_create() will be called to create all components in a single query
                          (default). Otherwise, save() will be called on each instance individually.
         """
-        components = [obj.instantiate(device=self) for obj in queryset]
-        if components and bulk_create:
+        if bulk_create:
+            components = [obj.instantiate(device=self) for obj in queryset]
+            if not components:
+                return
             model = components[0]._meta.model
             model.objects.bulk_create(components)
             # Manually send the post_save signal for each of the newly created components
@@ -788,8 +790,9 @@ def _instantiate_components(self, queryset, bulk_create=True):
                     using='default',
                     update_fields=None
                 )
-        elif components:
-            for component in components:
+        else:
+            for obj in queryset:
+                component = obj.instantiate(device=self)
                 component.save()
 
     def save(self, *args, **kwargs):


Test patch: