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

Issue:
Increment/Decrement Integer on Site AS Number Does not Function (Chrome/Safari)
### Environment
* Python version:  3.6.8
* NetBox version:  v2.7 beta1 & v2.7 beta2

<!--
    Describe in detail the exact steps that someone else can take to reproduce
    this bug using the current stable release of NetBox (or the current beta
    release where applicable). Begin with the creation of any necessary
    database objects and call out every operation being performed explicitly.
    If reporting a bug in the REST API, be sure to reconstruct the raw HTTP
    request(s) being made: Don't rely on a wrapper like pynetbox.
-->
### Steps to Reproduce
A. Open Google Chrome 79.0.3945.88 (MacOS)
1. Go to sites
2. Edit a site
3. Click on the integer increment button

Firefox works just fine. Safari has a whole different issue (report coming soon). Not sure if this is a browser function or a function of a library Netbox uses? 

<!-- What did you expect to happen? -->
### Expected Behavior
Expected to have the integers increment and decrement based on number of mouse clicks.

<!-- What happened instead? -->
### Observed Behavior
The number stays the same


Discussion:
This currently happens on the latest stable version, v2.6.11.
This seems to be caused by the `min` and `max` attributes being set to absurdly high numbers due to the `ASNField` inheriting from `models.BigIntegerField`. 
```html
<input type="number" name="asn" min="-9223372036854775808" max="9223372036854775807" class="form-control" placeholder="ASN" id="id_asn">
```

Resolving patch:
diff --git a/netbox/dcim/constants.py b/netbox/dcim/constants.py
--- a/netbox/dcim/constants.py
+++ b/netbox/dcim/constants.py
@@ -1,4 +1,8 @@
 
+# BGP ASN bounds
+BGP_ASN_MIN = 1
+BGP_ASN_MAX = 2**32 - 1
+
 # Rack types
 RACK_TYPE_2POST = 100
 RACK_TYPE_4POST = 200
diff --git a/netbox/dcim/fields.py b/netbox/dcim/fields.py
--- a/netbox/dcim/fields.py
+++ b/netbox/dcim/fields.py
@@ -3,14 +3,21 @@
 from django.db import models
 from netaddr import AddrFormatError, EUI, mac_unix_expanded
 
+from .constants import *
+
 
 class ASNField(models.BigIntegerField):
     description = "32-bit ASN field"
     default_validators = [
-        MinValueValidator(1),
-        MaxValueValidator(4294967295),
+        MinValueValidator(BGP_ASN_MIN),
+        MaxValueValidator(BGP_ASN_MAX),
     ]
 
+    def formfield(self, **kwargs):
+        defaults = {'min_value': BGP_ASN_MIN, 'max_value': BGP_ASN_MAX}
+        defaults.update(**kwargs)
+        return super().formfield(**defaults)
+
 
 class mac_unix_expanded_uppercase(mac_unix_expanded):
     word_fmt = '%.2X'
diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py
--- a/netbox/dcim/forms.py
+++ b/netbox/dcim/forms.py
@@ -292,8 +292,8 @@ class SiteBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditFor
         )
     )
     asn = forms.IntegerField(
-        min_value=1,
-        max_value=4294967295,
+        min_value=BGP_ASN_MIN,
+        max_value=BGP_ASN_MAX,
         required=False,
         label='ASN'
     )


Test patch:
Repository: netbox-community/netbox

Issue:
Error in webhook response to include response body
### Environment
* Python version:  3.5.2
* NetBox version:  2.6.3

### Proposed Functionality

At the point where a webhook gets a response code != 2xx, I would like the raised exception to include the response body (`response.text`) - or the first 1000 characters, say.  Alternatively, I'd like the response body to be logged before the exception is raised.

At the moment, all you get is the numeric code and the message "webhook FAILED to process".  Example captured from the django-rq admin page after selecting a failed job:

```
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/rq/worker.py", line 812, in perform_job
    rv = job.perform()
  File "/usr/local/lib/python3.5/dist-packages/rq/job.py", line 588, in perform
    self._result = self._execute()
  File "/usr/local/lib/python3.5/dist-packages/rq/job.py", line 594, in _execute
    return self.func(*self.args, **self.kwargs)
  File "/opt/netbox/netbox/extras/webhooks_worker.py", line 58, in process_webhook
    "Status {} returned, webhook FAILED to process.".format(response.status_code)
requests.exceptions.RequestException: Status 500 returned, webhook FAILED to process.
```

The [current code](https://github.com/netbox-community/netbox/blob/develop/netbox/extras/webhooks_worker.py#L54):

```
        raise requests.exceptions.RequestException(
            "Status {} returned, webhook FAILED to process.".format(response.status_code)
        )
```

### Use Case

Debugging individual job errors at `/admin/webhook-backend-status/`. The response body might include a useful error message, or even a backtrace from the other side, but this is currently lost.

### Database Changes

None

### External Dependencies

None



Discussion:

Resolving patch:
diff --git a/netbox/extras/webhooks_worker.py b/netbox/extras/webhooks_worker.py
--- a/netbox/extras/webhooks_worker.py
+++ b/netbox/extras/webhooks_worker.py
@@ -60,5 +60,5 @@ def process_webhook(webhook, data, model_name, event, timestamp, username, reque
         return 'Status {} returned, webhook successfully processed.'.format(response.status_code)
     else:
         raise requests.exceptions.RequestException(
-            "Status {} returned, webhook FAILED to process.".format(response.status_code)
+            "Status {} returned with content '{}', webhook FAILED to process.".format(response.status_code, response.content)
         )


Test patch:
Repository: netbox-community/netbox

Issue:
Regression from rack group filtering fix
### Environment
* Python version:  3.6.8
* NetBox version:  2.6.12-dev

### Steps to Reproduce
1. Navigate to `/dcim/rack-elevations/`

### Expected Behavior

Page loads

### Observed Behavior

Exception
```
<class 'KeyError'>

'rack_group_id'
```

This is a regression from https://github.com/netbox-community/netbox/commit/6bc8f2e50bc6e859064f24e4d78c396c70c8e0ca#diff-20da25434db0391c8eafd320dff942b3L742-R742.


Discussion:

Resolving patch:
diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py
--- a/netbox/dcim/forms.py
+++ b/netbox/dcim/forms.py
@@ -739,7 +739,7 @@ def __init__(self, *args, **kwargs):
 
         # Filter the rack field based on the site and group
         self.fields['site'].widget.add_filter_for('id', 'site')
-        self.fields['rack_group_id'].widget.add_filter_for('id', 'group_id')
+        self.fields['group_id'].widget.add_filter_for('id', 'group_id')
 
 
 #


Test patch:
Repository: netbox-community/netbox

Issue:
Message when disconnecting a cable not showing ID
### Environment
* Python version: 3.6.8
* NetBox version: 2.6.12-dev

### Steps to Reproduce
1. Go to a device (e.g. `dcim/devices/1/`)
2. Disconnect a cable

### Expected Behavior
The message says `Deleted cable #5` where 5 is the ID of the cable.

### Observed Behavior
The message says `#None`

This is similar to https://github.com/netbox-community/netbox/issues/2984


Discussion:

Resolving patch:
diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py
--- a/netbox/dcim/models.py
+++ b/netbox/dcim/models.py
@@ -3027,15 +3027,14 @@ class Meta:
             ('termination_b_type', 'termination_b_id'),
         )
 
-    def __str__(self):
-        if self.label:
-            return self.label
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
 
-        # Save a copy of the PK on the instance since it's nullified if .delete() is called
-        if not hasattr(self, 'id_string'):
-            self.id_string = '#{}'.format(self.pk)
+        # A copy of the PK to be used by __str__ in case the object is deleted
+        self._pk = self.pk
 
-        return self.id_string
+    def __str__(self):
+        return self.label or '#{}'.format(self._pk)
 
     def get_absolute_url(self):
         return reverse('dcim:cable', args=[self.pk])
@@ -3142,6 +3141,9 @@ def save(self, *args, **kwargs):
 
         super().save(*args, **kwargs)
 
+        # Update the private pk used in __str__ in case this is a new object (i.e. just got its pk)
+        self._pk = self.pk
+
     def to_csv(self):
         return (
             '{}.{}'.format(self.termination_a_type.app_label, self.termination_a_type.model),


Test patch:
diff --git a/netbox/dcim/tests/test_models.py b/netbox/dcim/tests/test_models.py
--- a/netbox/dcim/tests/test_models.py
+++ b/netbox/dcim/tests/test_models.py
@@ -325,9 +325,12 @@ def test_cable_creation(self):
 
     def test_cable_deletion(self):
         """
-        When a Cable is deleted, the `cable` field on its termination points must be nullified.
+        When a Cable is deleted, the `cable` field on its termination points must be nullified. The str() method
+        should still return the PK of the string even after being nullified.
         """
         self.cable.delete()
+        self.assertIsNone(self.cable.pk)
+        self.assertNotEqual(str(self.cable), '#None')
         interface1 = Interface.objects.get(pk=self.interface1.pk)
         self.assertIsNone(interface1.cable)
         interface2 = Interface.objects.get(pk=self.interface2.pk)
Repository: netbox-community/netbox

Issue:
Relax non-essential required fields when connecting
### Proposed Changes
Relax the non-essential required fields when connecting to a circuit terminations or a power feed (all other forms are fine).

### Justification
THe circuit terminations' provider field is set to required, although not everyone needs it, like if you knew the circuit ID already. Similarly, connecting to a power feed shouldn't require site and power panel; they're only there to allow you to filter down the final list of power feeds.

This will replicate the behaviour of other `ConnectCableTo` forms.


Discussion:

Resolving patch:
diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py
--- a/netbox/dcim/forms.py
+++ b/netbox/dcim/forms.py
@@ -2804,6 +2804,7 @@ class ConnectCableToCircuitTerminationForm(BootstrapMixin, ChainedFieldsMixin, f
     termination_b_provider = forms.ModelChoiceField(
         queryset=Provider.objects.all(),
         label='Provider',
+        required=False,
         widget=APISelect(
             api_url='/api/circuits/providers/',
             filter_for={
@@ -2857,6 +2858,7 @@ class ConnectCableToPowerFeedForm(BootstrapMixin, ChainedFieldsMixin, forms.Mode
     termination_b_site = forms.ModelChoiceField(
         queryset=Site.objects.all(),
         label='Site',
+        required=False,
         widget=APISelect(
             api_url='/api/dcim/sites/',
             display_field='cid',
@@ -2888,6 +2890,7 @@ class ConnectCableToPowerFeedForm(BootstrapMixin, ChainedFieldsMixin, forms.Mode
             ('rack_group', 'termination_b_rackgroup'),
         ),
         label='Power Panel',
+        required=False,
         widget=APISelect(
             api_url='/api/dcim/power-panels/',
             filter_for={


Test patch:
Repository: netbox-community/netbox

Issue:
Assign IP AttributeError
### Environment
* Python version:  3.6.8
* NetBox version:  2.7.0

### Steps to Reproduce
1. Go to assign IP page `http://netbox/ipam/ip-addresses/assign/?interface=1`
2. Attempt to search

### Expected Behavior

Results come back

### Observed Behavior

`AttributeError` due to `filters.IPAddressFilter` not being a valid filter (been renamed to `filters.IPAddressFilterSet`)


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
@@ -760,7 +760,7 @@ def post(self, request):
                 'vrf', 'tenant', 'interface__device', 'interface__virtual_machine'
             )
             # Limit to 100 results
-            addresses = filters.IPAddressFilter(request.POST, addresses).qs[:100]
+            addresses = filters.IPAddressFilterSet(request.POST, addresses).qs[:100]
             table = tables.IPAddressAssignTable(addresses)
 
         return render(request, 'ipam/ipaddress_assign.html', {


Test patch:
Repository: netbox-community/netbox

Issue:
Devices without names are displayed as None in the rack
### Environment
* Python version:  Any
* NetBox version:  >=2.7.0

As discussed in #3958, devices with no name are currently displayed as `None`. It used to show the device model instead, which is probably more helpful.

This should be a simple change to fix.

Cheers


Discussion:

Resolving patch:
diff --git a/netbox/dcim/models/__init__.py b/netbox/dcim/models/__init__.py
--- a/netbox/dcim/models/__init__.py
+++ b/netbox/dcim/models/__init__.py
@@ -397,12 +397,12 @@ def _draw_device_front(drawing, device, start, end, text):
         )
         link.add(drawing.rect(start, end, fill='#{}'.format(color)))
         hex_color = '#{}'.format(foreground_color(color))
-        link.add(drawing.text(device.name, insert=text, fill=hex_color))
+        link.add(drawing.text(str(device), insert=text, fill=hex_color))
 
     @staticmethod
     def _draw_device_rear(drawing, device, start, end, text):
         drawing.add(drawing.rect(start, end, class_="blocked"))
-        drawing.add(drawing.text(device.name, insert=text))
+        drawing.add(drawing.text(str(device), insert=text))
 
     @staticmethod
     def _draw_empty(drawing, rack, start, end, text, id_, face_id, class_):


Test patch:
Repository: netbox-community/netbox

Issue:
SVG rack elevations: racks seem unoccupied when other side is occupied
### Environment
* Python version:  Any
* NetBox version:  >=2.7.0

Quoting from #3958:
> When you view the front face of a rack, but there is a device in the corresponding rear position, you used to get some shading to indicate this. This no longer appears - it looks like the rack U is completely unoccupied.

I remember that this used to work, but it seems like it doesn’t anymore (haven’t been able to verify). We’ll have to investigate what happened there.

Cheers


Discussion:

Resolving patch:
diff --git a/netbox/dcim/models/__init__.py b/netbox/dcim/models/__init__.py
--- a/netbox/dcim/models/__init__.py
+++ b/netbox/dcim/models/__init__.py
@@ -459,6 +459,21 @@ def _draw_elevations(self, elevation, reserved_units, face, unit_width, unit_hei
 
         return drawing
 
+    def merge_elevations(self, face):
+        elevation = self.get_rack_units(face=face, expand_devices=False)
+        other_face = DeviceFaceChoices.FACE_FRONT if face == DeviceFaceChoices.FACE_REAR else DeviceFaceChoices.FACE_REAR
+        other = self.get_rack_units(face=other_face)
+
+        unit_cursor = 0
+        for u in elevation:
+            o = other[unit_cursor]
+            if not u['device'] and o['device']:
+                u['device'] = o['device']
+                u['height'] = 1
+            unit_cursor += u.get('height', 1)
+
+        return elevation
+
     def get_elevation_svg(self, face=DeviceFaceChoices.FACE_FRONT, unit_width=230, unit_height=20):
         """
         Return an SVG of the rack elevation
@@ -468,7 +483,7 @@ def get_elevation_svg(self, face=DeviceFaceChoices.FACE_FRONT, unit_width=230, u
         :param unit_height: Height of each rack unit for the rendered drawing. Note this is not the total
             height of the elevation
         """
-        elevation = self.get_rack_units(face=face, expand_devices=False)
+        elevation = self.merge_elevations(face)
         reserved_units = self.get_reserved_units().keys()
 
         return self._draw_elevations(elevation, reserved_units, face, unit_width, unit_height)


Test patch:
Repository: netbox-community/netbox

Issue:
SVG rack elevations: devices should have borders separating them
<!--
    NOTE: This form is only for reproducible bugs. If you need assistance with
    NetBox installation, or if you have a general question, DO NOT open an
    issue. Instead, post to our mailing list:

        https://groups.google.com/forum/#!forum/netbox-discuss

    Please describe the environment in which you are running NetBox. Be sure
    that you are running an unmodified instance of the latest stable release
    before submitting a bug report.
-->
### Environment
* Python version:  <!-- Example: 3.5.4 -->
* NetBox version:  <!-- Example: 2.5.2 -->

Quoting from #3958:
> For devices which are butted together and have the same role/colour, there is no longer any line separating them - see example below. This comprises two 2U boxes and a 4U box, but is now very hard to see.

![](https://user-images.githubusercontent.com/44789/72678862-bc35a780-3aa1-11ea-8c35-8db1f0d7209d.png)
SVG rack elevations: devices should have borders separating them
<!--
    NOTE: This form is only for reproducible bugs. If you need assistance with
    NetBox installation, or if you have a general question, DO NOT open an
    issue. Instead, post to our mailing list:

        https://groups.google.com/forum/#!forum/netbox-discuss

    Please describe the environment in which you are running NetBox. Be sure
    that you are running an unmodified instance of the latest stable release
    before submitting a bug report.
-->
### Environment
* Python version:  <!-- Example: 3.5.4 -->
* NetBox version:  <!-- Example: 2.5.2 -->

Quoting from #3958:
> For devices which are butted together and have the same role/colour, there is no longer any line separating them - see example below. This comprises two 2U boxes and a 4U box, but is now very hard to see.

![](https://user-images.githubusercontent.com/44789/72678862-bc35a780-3aa1-11ea-8c35-8db1f0d7209d.png)


Discussion:

Resolving patch:
diff --git a/netbox/dcim/models/__init__.py b/netbox/dcim/models/__init__.py
--- a/netbox/dcim/models/__init__.py
+++ b/netbox/dcim/models/__init__.py
@@ -399,7 +399,7 @@ def _draw_device_front(drawing, device, start, end, text):
             device.device_role, device.device_type.display_name,
             device.device_type.u_height, device.asset_tag or '', device.serial or ''
         ))
-        link.add(drawing.rect(start, end, fill='#{}'.format(color)))
+        link.add(drawing.rect(start, end, style='fill: #{}'.format(color), class_='slot'))
         hex_color = '#{}'.format(foreground_color(color))
         link.add(drawing.text(str(device), insert=text, fill=hex_color))
 


Test patch:
Repository: netbox-community/netbox

Issue:
SVG rack elevations don’t render tooltips anymore
### Environment
* Python version:  Any
* NetBox version:  >=2.7.0

As discussed in #3958, the tooltip isn’t rendered anymore inside rack elevations SVG models on hover. @candlerb pointed out that this could potentially be fixed with titles.

This needs some investigation as to how to fix this. I actually pointed this out in #3754, but we must’ve forgotten it somewhere along the process.

Cheers


Discussion:

Resolving patch:
diff --git a/netbox/dcim/models/__init__.py b/netbox/dcim/models/__init__.py
--- a/netbox/dcim/models/__init__.py
+++ b/netbox/dcim/models/__init__.py
@@ -395,13 +395,22 @@ def _draw_device_front(drawing, device, start, end, text):
                 fill='black'
             )
         )
+        link.set_desc('{} — {} ({}U) {} {}'.format(
+            device.device_role, device.device_type.display_name,
+            device.device_type.u_height, device.asset_tag or '', device.serial or ''
+        ))
         link.add(drawing.rect(start, end, fill='#{}'.format(color)))
         hex_color = '#{}'.format(foreground_color(color))
         link.add(drawing.text(str(device), insert=text, fill=hex_color))
 
     @staticmethod
     def _draw_device_rear(drawing, device, start, end, text):
-        drawing.add(drawing.rect(start, end, class_="blocked"))
+        rect = drawing.rect(start, end, class_="blocked")
+        rect.set_desc('{} — {} ({}U) {} {}'.format(
+            device.device_role, device.device_type.display_name,
+            device.device_type.u_height, device.asset_tag or '', device.serial or ''
+        ))
+        drawing.add(rect)
         drawing.add(drawing.text(str(device), insert=text))
 
     @staticmethod


Test patch:
Repository: netbox-community/netbox

Issue:
SVG rack elevations: No pop-ups for reserved units
### Environment
* Python version:  3.6.9
* NetBox version:  2.7.2

Previously you could hover over a reserved object and a window pops up with information about the tenant / description of this reservation.

### Expected Behavior
Pop-up appear over reserved unit on mouse hover.

### Observed Behavior
Pop-up not showing up.

![image](https://user-images.githubusercontent.com/7577925/72877687-26e51e00-3d02-11ea-8770-c58710f86b65.png)
![image](https://user-images.githubusercontent.com/7577925/72877719-306e8600-3d02-11ea-88b8-62b321fd123b.png)



Discussion:
@hellerve Do you want to take this one too? If not I'll give it a shot.
I can take this on; it shouldn’t be too hard!

Resolving patch:
diff --git a/netbox/dcim/models/__init__.py b/netbox/dcim/models/__init__.py
--- a/netbox/dcim/models/__init__.py
+++ b/netbox/dcim/models/__init__.py
@@ -414,7 +414,7 @@ def _draw_device_rear(drawing, device, start, end, text):
         drawing.add(drawing.text(str(device), insert=text))
 
     @staticmethod
-    def _draw_empty(drawing, rack, start, end, text, id_, face_id, class_):
+    def _draw_empty(drawing, rack, start, end, text, id_, face_id, class_, reservation):
         link = drawing.add(
             drawing.a(
                 href='{}?{}'.format(
@@ -424,6 +424,10 @@ def _draw_empty(drawing, rack, start, end, text, id_, face_id, class_):
                 target='_top'
             )
         )
+        if reservation:
+            link.set_desc('{} — {} · {}'.format(
+                reservation.description, reservation.user, reservation.created
+            ))
         link.add(drawing.rect(start, end, class_=class_))
         link.add(drawing.text("add device", insert=text, class_='add-device'))
 
@@ -453,12 +457,13 @@ def _draw_elevations(self, elevation, reserved_units, face, unit_width, unit_hei
             else:
                 # Draw shallow devices, reservations, or empty units
                 class_ = 'slot'
+                reservation = reserved_units.get(unit["id"])
                 if device:
                     class_ += ' occupied'
-                if unit["id"] in reserved_units:
+                if reservation:
                     class_ += ' reserved'
                 self._draw_empty(
-                    drawing, self, start_cordinates, end_cordinates, text_cordinates, unit["id"], face, class_
+                    drawing, self, start_cordinates, end_cordinates, text_cordinates, unit["id"], face, class_, reservation
                 )
 
             unit_cursor += height
@@ -493,7 +498,7 @@ def get_elevation_svg(self, face=DeviceFaceChoices.FACE_FRONT, unit_width=230, u
             height of the elevation
         """
         elevation = self.merge_elevations(face)
-        reserved_units = self.get_reserved_units().keys()
+        reserved_units = self.get_reserved_units()
 
         return self._draw_elevations(elevation, reserved_units, face, unit_width, unit_height)
 


Test patch: