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

Issue:
error when filtering choice sets when editing/creating a custom field
### NetBox version

v.3.6.4

### Python version

3.11

### Steps to Reproduce

- create a custom field choice set
- start creating a custom field. attempt to search in the "choice set" field.


UI error should pop up (or see a failure in browser debug window
error can easily be triggered by going to `/api/extras/custom-field-choice-sets/?brief=true&q=abc` on a netbox instance

### Expected Behavior

choice set should filter 

### Observed Behavior

error is triggered in browser

```
<class 'django.db.utils.DataError'>

malformed array literal: "abc"
LINE 1: ... "extras_customfieldchoiceset"."extra_choices" @> 'abc'::var...
                                                             ^
DETAIL:  Array value must start with "{" or dimension information.

Python version: 3.11.4
NetBox version: 3.6.4
Plugins: 
  netbox_gateways: 0.4.3
```

<img width="1107" alt="Screenshot 2023-11-09 at 21 41 43" src="https://github.com/netbox-community/netbox/assets/1613241/333911b5-18fa-4fc7-bd9c-99d5f52dd535">


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
@@ -122,8 +122,7 @@ def search(self, queryset, name, value):
             return queryset
         return queryset.filter(
             Q(name__icontains=value) |
-            Q(description__icontains=value) |
-            Q(extra_choices__contains=value)
+            Q(description__icontains=value)
         )
 
     def filter_by_choice(self, queryset, name, value):


Test patch:
Repository: netbox-community/netbox

Issue:
Remove the `clearcache` management command
### Proposed Changes

Remove the `clearcache` management command (from the `core` app), and omit it from the upgrade script.

### Justification

~This command was introduced back when we were experimenting with query caching, and is no longer needed.~ I was mistaken; it was actually introduced under #9122 to provide a mechanism for clearing the cached API spec. However, this is also no longer used since we moved to `drf-spectacular` (see #9608).

The Django cache is currently used only for discrete caching operations, including:

* Config revision tracking
* Recording the most recent release
* Caching RSS feed content (the RSSFeedWidget)

There has already been at least one bug related to this function (see #14182). Additionally, plugins may utilize the cache for other purposes, and we cannot make the assumption that it is safe to clear other cached data.

### Impact

Any mechanisms within NetBox or a plugin which employ caching will be responsible for their own cleanup, where applicable.


Discussion:

Resolving patch:
diff --git a/netbox/core/management/commands/clearcache.py b/netbox/core/management/commands/clearcache.py
deleted file mode 100644
--- a/netbox/core/management/commands/clearcache.py
+++ /dev/null
@@ -1,20 +0,0 @@
-from django.core.cache import cache
-from django.core.management.base import BaseCommand
-
-from core.models import ConfigRevision
-
-
-class Command(BaseCommand):
-    """Command to clear the entire cache."""
-    help = 'Clears the cache.'
-
-    def handle(self, *args, **kwargs):
-        # Fetch the current config revision from the cache
-        config_version = cache.get('config_version')
-        # Clear the cache
-        cache.clear()
-        self.stdout.write('Cache has been cleared.', ending="\n")
-        if config_version:
-            # Activate the current config revision
-            ConfigRevision.objects.get(id=config_version).activate()
-            self.stdout.write(f'Config revision ({config_version}) has been restored.', ending="\n")


Test patch:
Repository: netbox-community/netbox

Issue:
Cannot move primary IP from device to VM or vice versa
### Deployment Type

Self-hosted

### NetBox Version

v3.6.6

### Python Version

3.8

### Steps to Reproduce

1. Add an IP to a device and set it as the device's primary IP address
2. On a VM interface, assign the IP from step 1 and check "Make this the primary IP for the device/VM"
3. On save, a `ValueError` is raised

This bug also works the other way around (VM to Device).

### Expected Behavior

The IP address should be assigned to the VM interface.

### Observed Behavior

```
<class 'ValueError'>

'IPAddressForm' has no field named 'assigned_object'.

Python version: 3.8.10
NetBox version: 3.6.6
Plugins: 
  netbox_demo: 0.3.1
```


Discussion:
To be clear, moving the primary IP for a device/VM is *not* supported. However, attempting to do so should return a validation error rather than raise an exception.

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
@@ -864,11 +864,9 @@ def clean(self):
                 is_primary = True
 
             if is_primary and (parent != original_parent):
-                raise ValidationError({
-                    'assigned_object': _(
-                        "Cannot reassign IP address while it is designated as the primary IP for the parent object"
-                    )
-                })
+                raise ValidationError(
+                    _("Cannot reassign IP address while it is designated as the primary IP for the parent object")
+                )
 
         # Validate IP status selection
         if self.status == IPAddressStatusChoices.STATUS_SLAAC and self.family != 6:


Test patch:
Repository: netbox-community/netbox

Issue:
Quick search not working on VLAN group -> VLANs view
### Deployment Type

Self-hosted

### NetBox Version

v3.6.6

### Python Version

3.8

### Steps to Reproduce

1. Go to the detail view of one of your VLAN groups
2. Go to the tab VLAN (example: https://demo.netbox.dev/ipam/vlan-groups/2/vlans/)
3. Try using the quick search to find any info in the list

### Expected Behavior

The list to filter on the quick search input

### Observed Behavior

Nothing happens. 


Discussion:

Resolving patch:
diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py
--- a/netbox/ipam/views.py
+++ b/netbox/ipam/views.py
@@ -953,7 +953,7 @@ def get_children(self, request, parent):
 
     def prep_table_data(self, request, queryset, parent):
         if not get_table_ordering(request, self.table):
-            return add_available_vlans(parent.get_child_vlans(), parent)
+            return add_available_vlans(queryset, parent)
         return queryset
 
 


Test patch:
Repository: netbox-community/netbox

Issue:
Setting Tags in Virtual Device Contexts and displaying the Tags column causes an error
### Deployment Type

Self-hosted

### NetBox Version

v3.6.7

### Python Version

3.8

### Steps to Reproduce

1. Add a new virtual device context with tags
![Add](https://github.com/netbox-community/netbox/assets/20819471/eeaed5c9-5097-4472-b06f-7000fbd3dc4b)
1. Navigate to "Virtual Device Contexts" and press the "Configure Table" button.
1. Add the Tags column and press Save.
![Add the Tags column](https://github.com/netbox-community/netbox/assets/20819471/fdf26c28-ec38-482b-9508-3d4426617b46)
1. A NoReverseMatch Exception was raised
![Causes an error](https://github.com/netbox-community/netbox/assets/20819471/99d50350-c326-4f77-b0f7-694a69aa8b9b)

> Server Error
> There was a problem with your request. Please contact an administrator.
> 
> The complete exception is provided below:
> 
> <class 'django.urls.exceptions.NoReverseMatch'>
> 
> Reverse for 'vdc_list' not found. 'vdc_list' is not a valid view function or pattern name.
> 
> Python version: 3.8.10
> NetBox version: 3.6.7
> Plugins: 
>   netbox_demo: 0.3.1
> If further assistance is required, please post to the NetBox discussion forum on GitHub.

### Expected Behavior

The Virtual Device Contexts with the added Tags column are displayed.

### Observed Behavior

A NoReverseMatch Exception was raised


Discussion:
In `netbox/dcim/tables/devices.py`, the url_name is defined as `dcim:vdc_list`, but I think it should correctly be  `dcim:virtualdevicecontext_list`.

https://github.com/netbox-community/netbox/blob/12beac4f1adc5be8dba927f9823e0bd904dcf60f/netbox/dcim/tables/devices.py#L1080C1-L1082C6
https://github.com/netbox-community/netbox/blob/12beac4f1adc5be8dba927f9823e0bd904dcf60f/netbox/dcim/urls.py#L186

After making the above changes, it is functioning as expected in my environment.

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
@@ -1078,7 +1078,7 @@ class VirtualDeviceContextTable(TenancyColumnsMixin, NetBoxTable):
     comments = columns.MarkdownColumn()
 
     tags = columns.TagColumn(
-        url_name='dcim:vdc_list'
+        url_name='dcim:virtualdevicecontext_list'
     )
 
     class Meta(NetBoxTable.Meta):


Test patch:
Repository: netbox-community/netbox

Issue:
Add a link to the parent Prefix in IP Ranges
### NetBox version

v.3.3.6

### Feature type

Change to existing functionality

### Proposed functionality

I want to see the parent prefix of an IP range when I look at my IP range (https://mynetbox/ipam/ip-ranges/2/)
A simple way to implement that is to display the prefix of a random IP in the range, but it will not work if the range goes through multiple prefixes.

### Use case

We want to move our "fake" prefixes to IP ranges, but it's hard to know the parent prefix of an IP Address.


### Database changes

It should be a computed value and shouldn't change the database

### External dependencies

No dependencies


Discussion:
This is implemented in #10692.
Marking this as blocked by #7845. We need to determine an efficient way of automatically mapping child IP addresses, ranges, and prefixes to their parent prefixes.
Absent a solution for #7845, we can just do what we do for IP prefixes currently: Dynamically resolve any containing prefixes and list them in a table on the page.

Resolving patch:
diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py
--- a/netbox/ipam/views.py
+++ b/netbox/ipam/views.py
@@ -661,6 +661,26 @@ class IPRangeListView(generic.ObjectListView):
 class IPRangeView(generic.ObjectView):
     queryset = IPRange.objects.all()
 
+    def get_extra_context(self, request, instance):
+
+        # Parent prefixes table
+        parent_prefixes = Prefix.objects.restrict(request.user, 'view').filter(
+            Q(prefix__net_contains_or_equals=str(instance.start_address.ip)),
+            Q(prefix__net_contains_or_equals=str(instance.end_address.ip)),
+            vrf=instance.vrf
+        ).prefetch_related(
+            'site', 'role', 'tenant', 'vlan', 'role'
+        )
+        parent_prefixes_table = tables.PrefixTable(
+            list(parent_prefixes),
+            exclude=('vrf', 'utilization'),
+            orderable=False
+        )
+
+        return {
+            'parent_prefixes_table': parent_prefixes_table,
+        }
+
 
 @register_model_view(IPRange, 'ipaddresses', path='ip-addresses')
 class IPRangeIPAddressesView(generic.ObjectChildrenView):


Test patch:
Repository: netbox-community/netbox

Issue:
Attaching a cloneable multi selection custom field with custom field choices breaks the Clone function
### NetBox version

v3.6.3

### Python version

3.9

### Steps to Reproduce

1. Create a custom field choices object without base choices selected and with at least 1 extra choice defined.
2. Create a custom field of the type "Multiple Selection" and associate with a content type (I used Virtual Machine, but the problem also appears for all other object types I've tested with such as IP addresses). 
3. Use the previously created custom field choices object as "Choice Set".
4. Select the "Is cloneable" checkbox.
5. Go to any object of the associated content type and try to clone it. It doesn't matter if the custom field has been provided with a value for that object or not.
6. Cloning will fail with the message `<class 'TypeError'> 'in <string>' requires string as left operand, not NoneType`
7. Disable the "Is cloneable" checkbox in the custom field that was created in step 2.
8. Cloning the object will now work (but obviously without cloning the custom field).

### Expected Behavior

I would expect the object to be cloneable when I use custom fields of the multiple selection type with the cloneable option enabled.

### Observed Behavior

`<class 'TypeError'>'in <string>' requires string as left operand, not NoneType` occurs whenever trying to clone any object that uses a multiple selection custom field where "is cloneable" is enabled.

This worked fine in 3.5.9, so it seems it is probably related to the new custom field choices object introduced in 3.6.0.

The workaround for now is to disable "is cloneable" on all multiple selection custom fields until the cause of the error is fixed.


Discussion:
can you pleas assign this task to me.

Resolving patch:
diff --git a/netbox/utilities/forms/fields/dynamic.py b/netbox/utilities/forms/fields/dynamic.py
--- a/netbox/utilities/forms/fields/dynamic.py
+++ b/netbox/utilities/forms/fields/dynamic.py
@@ -43,7 +43,7 @@ def get_bound_field(self, form, field_name):
 
         if data is not None:
             self.choices = [
-                choice for choice in self.choices if choice[0] in data
+                choice for choice in self.choices if choice[0] and choice[0] in data
             ]
 
         return bound_field


Test patch:
Repository: netbox-community/netbox

Issue:
Newest config revision displayed as current config even if not active
### Deployment Type

Self-hosted

### NetBox Version

v3.6.7

### Python Version

3.10

### Steps to Reproduce

1. Create a config revision by setting the top banner to "revision 1"
2. Edit the config and modify the top banner to "revision 2"
3. View the list of config revisions to verify that the second revision is active
4. Restore the first revision and verify that it is active
5. Click the "current config" link under the admin menu

### Expected Behavior

The parameters from the first revision should be displayed.

### Observed Behavior

The second (inactive) revision is displayed.


Discussion:

Resolving patch:
diff --git a/netbox/core/views.py b/netbox/core/views.py
--- a/netbox/core/views.py
+++ b/netbox/core/views.py
@@ -1,4 +1,5 @@
 from django.contrib import messages
+from django.core.cache import cache
 from django.shortcuts import get_object_or_404, redirect
 
 from extras.models import ConfigRevision
@@ -153,9 +154,11 @@ class ConfigView(generic.ObjectView):
     queryset = ConfigRevision.objects.all()
 
     def get_object(self, **kwargs):
-        if config := self.queryset.first():
-            return config
-        # Instantiate a dummy default config if none has been created yet
-        return ConfigRevision(
-            data=get_config().defaults
-        )
+        revision_id = cache.get('config_version')
+        try:
+            return ConfigRevision.objects.get(pk=revision_id)
+        except ConfigRevision.DoesNotExist:
+            # Fall back to using the active config data if no record is found
+            return ConfigRevision(
+                data=get_config()
+            )


Test patch:
Repository: netbox-community/netbox

Issue:
Increase custom field integer ranges (from 32bit signed int to 64bit signed int)
### NetBox version

v3.5.9

### Feature type

Change to existing functionality

### Proposed functionality

Allow values in the range supported by a 32 u-int, when creating a custom fields which are of type "integer".

Currently, the maximum value I can put in an "integer" custom field is for a signed 32bit int.

Maybe the solution is to bump the field to a be a 64-bit signed int, if you want to support negative numbers too?

Example:

![Bildschirmfoto vom 2023-11-10 10-07-35](https://github.com/netbox-community/netbox/assets/1025875/818e74d8-e281-4361-ae8c-d22d36a384fd)


### Use case

I want to store a BGP ASN number, which is a 32bit u-int.
I want to store a BGP Local Pref, which is a 32bit u-int.


### Database changes

I assume some sort of schema change is required but I don't know, sorry.

### External dependencies

Sorry, I don't know of any.


Discussion:

Resolving patch:
diff --git a/netbox/extras/migrations/0105_customfield_min_max_values.py b/netbox/extras/migrations/0105_customfield_min_max_values.py
new file mode 100644
--- /dev/null
+++ b/netbox/extras/migrations/0105_customfield_min_max_values.py
@@ -0,0 +1,23 @@
+# Generated by Django 4.2.8 on 2023-12-27 20:24
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('extras', '0104_stagedchange_remove_change_logging'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='customfield',
+            name='validation_maximum',
+            field=models.BigIntegerField(blank=True, null=True),
+        ),
+        migrations.AlterField(
+            model_name='customfield',
+            name='validation_minimum',
+            field=models.BigIntegerField(blank=True, null=True),
+        ),
+    ]
diff --git a/netbox/extras/models/customfields.py b/netbox/extras/models/customfields.py
--- a/netbox/extras/models/customfields.py
+++ b/netbox/extras/models/customfields.py
@@ -156,13 +156,13 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
         verbose_name=_('display weight'),
         help_text=_('Fields with higher weights appear lower in a form.')
     )
-    validation_minimum = models.IntegerField(
+    validation_minimum = models.BigIntegerField(
         blank=True,
         null=True,
         verbose_name=_('minimum value'),
         help_text=_('Minimum allowed value (for numeric fields)')
     )
-    validation_maximum = models.IntegerField(
+    validation_maximum = models.BigIntegerField(
         blank=True,
         null=True,
         verbose_name=_('maximum value'),


Test patch:
Repository: netbox-community/netbox

Issue:
Cannot resolve keyword 'description_icontains' into field
### Deployment Type

Self-hosted

### NetBox Version

v3.6.8

### Python Version

3.8

### Steps to Reproduce

1. Click on `Add Interface`
2. Type any characters in the combo-box `Select Device` 

### Expected Behavior

A list of devices shown

### Observed Behavior

Respond with HTTP 500
```<class 'django.core.exceptions.FieldError'>

Cannot resolve keyword 'description_icontains' into field. Choices are: _name, airflow, asset_tag, assigned_asset, bgpsession, bookmarks, cabletermination, cluster, cluster_id, comments, config_template, config_template_id, console_port_count, console_server_port_count, consoleports, consoleserverports, contacts, coordinate, created, custom_field_data, description, device_bay_count, device_type, device_type_id, devicebays, face, front_port_count, frontports, id, images, interface_count, interfaces, inventory_item_count, inventoryitems, journal_entries, last_updated, latitude, local_context_data, location, location_id, longitude, module_bay_count, modulebays, modules, name, oob_ip, oob_ip_id, parent_bay, platform, platform_id, position, power_outlet_count, power_port_count, poweroutlets, powerports, primary_ip4, primary_ip4_id, primary_ip6, primary_ip6_id, rack, rack_id, rear_port_count, rearports, role, role_id, serial, services, site, site_id, status, tagged_items, tags, tenant, tenant_id, vc_master_for, vc_position, vc_priority, vdcs, virtual_chassis, virtual_chassis_id, virtual_machines

Python version: 3.11.4
NetBox version: 3.6.8
Plugins: 
  netbox_bgp: 0.11.1
  netbox_contract: 2.0.9
  netbox_inventory: 1.5.2
  netbox_topology_views: 3.8.1
```


Discussion:

Resolving patch:
diff --git a/netbox/dcim/filtersets.py b/netbox/dcim/filtersets.py
--- a/netbox/dcim/filtersets.py
+++ b/netbox/dcim/filtersets.py
@@ -1018,7 +1018,7 @@ def search(self, queryset, name, value):
             Q(serial__icontains=value.strip()) |
             Q(inventoryitems__serial__icontains=value.strip()) |
             Q(asset_tag__icontains=value.strip()) |
-            Q(description_icontains=value.strip()) |
+            Q(description__icontains=value.strip()) |
             Q(comments__icontains=value) |
             Q(primary_ip4__address__startswith=value) |
             Q(primary_ip6__address__startswith=value)


Test patch:
Repository: netbox-community/netbox

Issue:
Remove backward compatibility for importing `process_webhook()`
### Proposed Changes

`extras.webhooks_worker.process_webhook()` was renamed and moved to `extras.webhooks.send_webhook() in v3.7 under #14395, with backward compatibility being retained for importing the function from its previous location. This change removes that backward compatibility.

### Justification

Removes obsolete code

### Impact

Any plugins which utilize this function imported from its previous location & name will need to be updated to reference the new path. (This function is _not_ supported for direct use by plugins, but we provided backward compatibility across v3.7 releases just in case.)


Discussion:

Resolving patch:
diff --git a/netbox/extras/webhooks_worker.py b/netbox/extras/webhooks_worker.py
deleted file mode 100644
--- a/netbox/extras/webhooks_worker.py
+++ /dev/null
@@ -1,10 +0,0 @@
-import warnings
-
-from .webhooks import send_webhook as process_webhook
-
-
-# TODO: Remove in v4.0
-warnings.warn(
-    f"webhooks_worker.process_webhook has been moved to webhooks.send_webhook.",
-    DeprecationWarning
-)


Test patch: