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

Issue:
Render Config Contexts as YAML in GUI
<!--
    NOTE: This form is only for proposing specific new features or enhancements.
    If you have a general idea or question, please post to our mailing list
    instead of opening an issue:

        https://groups.google.com/forum/#!forum/netbox-discuss

    NOTE: Due to an excessive backlog of feature requests, we are not currently
    accepting any proposals which significantly extend NetBox's feature scope.

    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:  3.6.8<!-- Example: 3.5.4 -->
* NetBox version:  2.5.13<!-- Example: 2.3.6 -->

<!--
    Describe in detail the new functionality you are proposing. Include any
    specific changes to work flows, data models, or the user interface.
-->
### Proposed Functionality
When creating/viewing configuration contexts via the Netbox GUI, allow for using YAML instead of JSON.

<!--
    Convey an example use case for your proposed feature. Write from the
    perspective of a NetBox user who would benefit from the proposed
    functionality and describe how.
--->
### Use Case
YAML is more human readable and easier to type/format when manually editing. Since YAML is a superset of JSON, the API would still use JSON and the storage would still be done as JSON - this would purely be for frontend rendering.

<!--
    Note any changes to the database schema necessary to support the new
    feature. For example, does the proposal require adding a new model or
    field? (Not all new features require database changes.)
--->
### Database Changes
N/A

<!--
    List any new dependencies on external libraries or services that this new
    feature would introduce. For example, does the proposal require the
    installation of a new Python package? (Not all new features introduce new
    dependencies.)
-->
### External Dependencies

Likely one of these:
- ruamel.yaml
- pyyaml


Discussion:

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
@@ -1,6 +1,7 @@
 import datetime
 import json
 import re
+import yaml
 
 from django import template
 from django.utils.html import strip_tags
@@ -76,6 +77,14 @@ def render_json(value):
     return json.dumps(value, indent=4, sort_keys=True)
 
 
+@register.filter()
+def render_yaml(value):
+    """
+    Render a dictionary as formatted YAML.
+    """
+    return yaml.dump(dict(value))
+
+
 @register.filter()
 def model_name(obj):
     """


Test patch:
Repository: netbox-community/netbox

Issue:
Add VRF to drop-down when selecting IP addresses
<!--
    NOTE: This form is only for proposing specific new features or enhancements.
    If you have a general idea or question, please post to our mailing list
    instead of opening an issue:

        https://groups.google.com/forum/#!forum/netbox-discuss

    NOTE: Due to an excessive backlog of feature requests, we are not currently
    accepting any proposals which significantly extend NetBox's feature scope.

    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:  3.6.9
* NetBox version: v2.6.12

<!--
    Describe in detail the new functionality you are proposing. Include any
    specific changes to work flows, data models, or the user interface.
-->
Add the VRF name (or some other identifying value) to the drop-down box for IP addresses so that duplicate IPs can be differentiated


<!--
    Convey an example use case for your proposed feature. Write from the
    perspective of a NetBox user who would benefit from the proposed
    functionality and describe how.
--->
When adding a NAT entry and selecting the corresponding IP address, all IPs are shown with only the CIDR notation displayed. When the same IP is in the database under different VRFs, there is no way to differentiate when looking at the IPs in the drop-down field. Having the VRF name appended to the IP address, or a field to enter the desired VRF and limit the results, would help users to know which IP they're selecting. 





Discussion:
Screenshot for example, 10.79.10.1/28 exists in two VRFs, but with this view I can't tell which one I'm actually selecting

![image](https://user-images.githubusercontent.com/13427789/72835283-6eaf6b00-3c58-11ea-94e5-1464fcb77da9.png)

I would accept this feature request as enhancement.

Resolving patch:
diff --git a/netbox/ipam/forms.py b/netbox/ipam/forms.py
--- a/netbox/ipam/forms.py
+++ b/netbox/ipam/forms.py
@@ -635,6 +635,17 @@ class IPAddressForm(BootstrapMixin, TenancyForm, ReturnURLForm, CustomFieldForm)
             }
         )
     )
+    nat_vrf = forms.ModelChoiceField(
+        queryset=VRF.objects.all(),
+        required=False,
+        label='VRF',
+        widget=APISelect(
+            api_url="/api/ipam/vrfs/",
+            filter_for={
+                'nat_inside': 'vrf_id'
+            }
+        )
+    )
     nat_inside = ChainedModelChoiceField(
         queryset=IPAddress.objects.all(),
         chains=(


Test patch:
Repository: netbox-community/netbox

Issue:
Override Django's management commands to suppress suggestion to create migrations
### Proposed Changes
Alter or remove some of Django's built-in management commands to simplify the process of applying schema migrations for users. It might be best to introduce a "developers only" configuration parameter, and simply remove the `makemigrations` command from the list of available commands unless that parameter is set.

### Justification
When a user does not follow the documented upgrade procedure, they may encounter a scenario where Django warns them of missing migrations, and prompts them to create new migrations. As this should *never* be required of an end user, we should remove that ability to help preserve the integrity of the installation environment.


Discussion:

Resolving patch:
diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py
--- a/netbox/netbox/settings.py
+++ b/netbox/netbox/settings.py
@@ -74,6 +74,7 @@
 DATE_FORMAT = getattr(configuration, 'DATE_FORMAT', 'N j, Y')
 DATETIME_FORMAT = getattr(configuration, 'DATETIME_FORMAT', 'N j, Y g:i a')
 DEBUG = getattr(configuration, 'DEBUG', False)
+DEVELOPER = getattr(configuration, 'DEVELOPER', False)
 EMAIL = getattr(configuration, 'EMAIL', {})
 ENFORCE_GLOBAL_UNIQUE = getattr(configuration, 'ENFORCE_GLOBAL_UNIQUE', False)
 EXEMPT_VIEW_PERMISSIONS = getattr(configuration, 'EXEMPT_VIEW_PERMISSIONS', [])
diff --git a/netbox/utilities/management/commands/makemigrations.py b/netbox/utilities/management/commands/makemigrations.py
--- a/netbox/utilities/management/commands/makemigrations.py
+++ b/netbox/utilities/management/commands/makemigrations.py
@@ -1,7 +1,28 @@
 # noinspection PyUnresolvedReferences
-from django.core.management.commands.makemigrations import Command
+from django.conf import settings
+from django.core.management.base import CommandError
+from django.core.management.commands.makemigrations import Command as _Command
 from django.db import models
 
 from . import custom_deconstruct
 
 models.Field.deconstruct = custom_deconstruct
+
+
+class Command(_Command):
+
+    def handle(self, *args, **kwargs):
+        """
+        This built-in management command enables the creation of new database schema migration files, which should
+        never be required by and ordinary user. We prevent this command from executing unless the configuration
+        indicates that the user is a developer (i.e. configuration.DEVELOPER == True).
+        """
+        if not settings.DEVELOPER:
+            raise CommandError(
+                "This command is available for development purposes only. It will\n"
+                "NOT resolve any issues with missing or unapplied migrations. For assistance,\n"
+                "please post to the NetBox mailing list:\n"
+                "    https://groups.google.com/forum/#!forum/netbox-discuss"
+            )
+
+        super().handle(*args, **kwargs)


Test patch:
Repository: netbox-community/netbox

Issue:
YAML rendering for config contexts with overlapping nested dictionary is incorrect
### Environment
* Python version:  3.7.3 
* NetBox version:  2.7.4

### Steps to Reproduce
1. Create config context region1
```
{
    "attributes": {
        "key10": "value10"
    }
}
```
2. Create config context site1
```
{
    "attributes": {
        "key20": "value20"
    }
}
```
3. These config contexts should be applied to the same device

<!-- What did you expect to happen? -->
### Expected rendered context
```
attributes:
  key10: value10
  key20: value20
```

<!-- What happened instead? -->
### Observed rendered context
```
attributes: !!python/object/apply:collections.OrderedDict
- - - key10
    - value10
  - - key20
    - value20
```



Discussion:
@hSaria I believe you did the YAML formatting, is this something you could look at?
Sure thing. I’ll take care of it.

> On 12 Feb 2020, at 17:58, Daniel Sheppard <notifications@github.com> wrote:
> 
> ﻿
> @hSaria I believe you did the YAML formatting, is this something you could look at?
> 
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub, or unsubscribe.


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
@@ -82,7 +82,7 @@ def render_yaml(value):
     """
     Render a dictionary as formatted YAML.
     """
-    return yaml.dump(dict(value))
+    return yaml.dump(json.loads(json.dumps(value)))
 
 
 @register.filter()


Test patch:
Repository: netbox-community/netbox

Issue:
IP Prefix Family returned doesn't match swagger definition
### Environment
* Python version:   3.7.6
* NetBox version:  v2.7.7

Swagger definition for Prefix.Family does not match the swagger definition.

### Steps to Reproduce
1. Get a prefix object `wget http://netbox/api/ipam/prefixes/210/`
2. Notice object is like
```
  "family": {
    "value": 4,
    "label": "IPv4"
  },
```
3. Notice definition is
```
  "family": {
    "label": "string",
    "value": "string"
  },
```


<!-- What did you expect to happen? -->
### Expected Behavior
Object returned matches definition. I'm not sure if the definition needs to be fixed or the returned value type needs to be changed.

<!-- What happened instead? -->
### Observed Behavior
Object doesn't match definition


Discussion:
cc @wbean1
What specifically are you calling out here? The ordering of the fields or the data type returned for the `value` key?
`value` is returned as an integer and not a string as the swagger definition calls out. According the swagger the prefix family should be:

```
"family": {
    "value": "4",
    "label": "IPv4"
  },
```

Or if the returned type is correct then the swagger should be:
```
  "family": {
    "label": "string",
    "value": "integer"
  },
```
ChoiceField which contains `int` values like `IPAddressFamilyChoices` and `RackWidthChoices` has the same issue.

Resolving patch:
diff --git a/netbox/utilities/custom_inspectors.py b/netbox/utilities/custom_inspectors.py
--- a/netbox/utilities/custom_inspectors.py
+++ b/netbox/utilities/custom_inspectors.py
@@ -89,6 +89,10 @@ def field_to_swagger_object(self, field, swagger_object_type, use_references, **
                 value_schema = openapi.Schema(type=schema_type)
                 value_schema['x-nullable'] = True
 
+            if isinstance(choices[0], int):
+                # Change value_schema for IPAddressFamilyChoices, RackWidthChoices
+                value_schema = openapi.Schema(type=openapi.TYPE_INTEGER)
+
             schema = SwaggerType(type=openapi.TYPE_OBJECT, required=["label", "value"], properties={
                 "label": openapi.Schema(type=openapi.TYPE_STRING),
                 "value": value_schema


Test patch:
Repository: netbox-community/netbox

Issue:
Clean up template tags and filters
### Proposed Changes
- Remove any unused template tags/filters
- Reorganize and document what's left

### Justification
General cleanup


Discussion:

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
@@ -20,15 +20,6 @@
 # Filters
 #
 
-@register.filter()
-def oneline(value):
-    """
-    Replace each line break with a single space
-    """
-    value = value.replace('\r', '')
-    return value.replace('\n', ' ')
-
-
 @register.filter()
 def placeholder(value):
     """
@@ -40,25 +31,8 @@ def placeholder(value):
     return mark_safe(placeholder)
 
 
-@register.filter()
-def getlist(value, arg):
-    """
-    Return all values of a QueryDict key
-    """
-    return value.getlist(arg)
-
-
-@register.filter
-def getkey(value, key):
-    """
-    Return a dictionary item specified by key
-    """
-    return value[key]
-
-
-# TODO: Rename this filter as py-gfm is no longer in use
 @register.filter(is_safe=True)
-def gfm(value):
+def render_markdown(value):
     """
     Render text as Markdown
     """
@@ -88,19 +62,12 @@ def render_yaml(value):
 
 
 @register.filter()
-def model_name(obj):
-    """
-    Return the name of the model of the given object
-    """
-    return obj._meta.verbose_name
-
-
-@register.filter()
-def model_name_plural(obj):
+def meta(obj, attr):
     """
-    Return the plural name of the model of the given object
+    Return the specified Meta attribute of a model. This is needed because Django does not permit templates
+    to access attributes which begin with an underscore (e.g. _meta).
     """
-    return obj._meta.verbose_name_plural
+    return getattr(obj._meta, attr, '')
 
 
 @register.filter()
@@ -118,14 +85,6 @@ def url_name(model, action):
         return None
 
 
-@register.filter()
-def contains(value, arg):
-    """
-    Test whether a value contains any of a given set of strings. `arg` should be a comma-separated list of strings.
-    """
-    return any(s in value for s in arg.split(','))
-
-
 @register.filter()
 def bettertitle(value):
     """


Test patch:
Repository: netbox-community/netbox

Issue:
Import of Device Type strips comments
### Environment
* Python version: any
* NetBox version: 2.8.1 & 2.8.4

<!--
    Describe in detail the exact steps that someone else can take to reproduce
    this bug using the current stable release of NetBox. 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 client
    library such as pynetbox.
-->
### Steps to Reproduce
1. Disable any installed plugins by commenting out the `PLUGINS` setting in
   `configuration.py`.
2. Add device type via YAML import that has comments. Simple example for testing:

```
manufacturer: Cisco
model: Switch_with_comments
slug: testSwitch
u_height: 1
is_full_depth: false
comments: disappear
interfaces:
- name: ge1/0/0
  type: 1000base-t
  mgmt_only: false

```

<!-- What did you expect to happen? -->
### Expected Behavior
New device type includes the comments

<!-- What happened instead? -->
### Observed Behavior
All details except comments are imported correctly. Comments section is blank. 
No error shown.

### Notes
I only have access to a v2.8.1 environment (my production) and v2.8.4 ([netboxdemo.com](https://netboxdemo.com/)). This issue may have existed in prior releases.

This is my first bug report. Please feel free to suggest improvements.



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
@@ -932,6 +932,7 @@ class Meta:
         model = DeviceType
         fields = [
             'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role',
+            'comments',
         ]
 
 


Test patch:
diff --git a/netbox/dcim/tests/test_views.py b/netbox/dcim/tests/test_views.py
--- a/netbox/dcim/tests/test_views.py
+++ b/netbox/dcim/tests/test_views.py
@@ -366,6 +366,7 @@ def test_import_objects(self):
 model: TEST-1000
 slug: test-1000
 u_height: 2
+comments: test comment
 console-ports:
   - name: Console Port 1
     type: de-9
@@ -456,6 +457,7 @@ def test_import_objects(self):
         self.assertHttpStatus(response, 200)
 
         dt = DeviceType.objects.get(model='TEST-1000')
+        self.assertEqual(dt.comments, 'test comment')
 
         # Verify all of the components were created
         self.assertEqual(dt.consoleport_templates.count(), 3)
Repository: netbox-community/netbox

Issue:
Swagger references IP address family incorrectly as string in NestedIPAddress.
<!--
    NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED.

    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, and that any plugins have been disabled.
-->
### Environment
* Python version: netbox-docker
* NetBox version: 2.8.6

<!--
    Describe in detail the exact steps that someone else can take to reproduce
    this bug using the current stable release of NetBox. 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 client
    library such as pynetbox.
-->
### Steps to Reproduce
1. Generate go-netbox with latest swagger https://github.com/netbox-community/go-netbox
2. Attempt to pull device information with dcim.DcimDevicesListParams on a device / rack that contains a primary ip configured on an device.
3. "cannot unmarshal number into Go struct field NestedIPAddress.results.primary_ip.family of type string"

<!-- What did you expect to happen? -->
### Expected Behavior
Swagger to match returned data.

<!-- What happened instead? -->
### Observed Behavior
Api returns Family as an number instead of a string, mismatching with swagger.
```
json: cannot unmarshal number into Go struct field NestedIPAddress.results.primary_ip.family of type string
```


Discussion:

Resolving patch:
diff --git a/netbox/ipam/api/nested_serializers.py b/netbox/ipam/api/nested_serializers.py
--- a/netbox/ipam/api/nested_serializers.py
+++ b/netbox/ipam/api/nested_serializers.py
@@ -44,6 +44,7 @@ class Meta:
 
 class NestedAggregateSerializer(WritableNestedSerializer):
     url = serializers.HyperlinkedIdentityField(view_name='ipam-api:aggregate-detail')
+    family = serializers.IntegerField(read_only=True)
 
     class Meta:
         model = models.Aggregate
@@ -87,6 +88,7 @@ class Meta:
 
 class NestedPrefixSerializer(WritableNestedSerializer):
     url = serializers.HyperlinkedIdentityField(view_name='ipam-api:prefix-detail')
+    family = serializers.IntegerField(read_only=True)
 
     class Meta:
         model = models.Prefix
@@ -99,6 +101,7 @@ class Meta:
 
 class NestedIPAddressSerializer(WritableNestedSerializer):
     url = serializers.HyperlinkedIdentityField(view_name='ipam-api:ipaddress-detail')
+    family = serializers.IntegerField(read_only=True)
 
     class Meta:
         model = models.IPAddress


Test patch:
Repository: netbox-community/netbox

Issue:
Swagger doesn't show required field "prefix_length" in available-prefixes POST request
<!--
    Please indicate the nature of the change by placing an X in one of the
    boxes below.
-->
### Change Type
[X ] Addition
[ ] Correction
[ ] Deprecation
[ ] Cleanup (formatting, typos, etc.)

### Environment
NetBox version: 2.5.13

<!-- Describe the proposed change(s). -->
### Proposed Change

Add `prefix_length` field in Swagger docs, something like:

prefix_length* integer
title: Prefix length
Size of this prefix 

In /ipam/prefixes/{id}/available-prefixes/ POST request

![prefixes](https://user-images.githubusercontent.com/20525775/58911018-397cf980-8717-11e9-9964-d82a805f0778.png)




Discussion:
Marking this as blocked by #2769
The blocker seems to be resolved. I also faced that issue today.
Same here.  Using swagger codegen to create the client forces me to try to provide an entire WritablePrefix object as opposed to an object with a single field `prefix_length`. It may just be a matter of creating a new object with a single field to be used as the data to the POST.
@chbndrhnns @thadc23 If you're willing to commit to working on this I'm happy to assign you the issue.

Resolving patch:
diff --git a/netbox/ipam/api/views.py b/netbox/ipam/api/views.py
--- a/netbox/ipam/api/views.py
+++ b/netbox/ipam/api/views.py
@@ -74,6 +74,11 @@ class PrefixViewSet(CustomFieldModelViewSet):
     serializer_class = serializers.PrefixSerializer
     filterset_class = filters.PrefixFilterSet
 
+    def get_serializer_class(self):
+        if self.action == "available_prefixes" and self.request.method == "POST":
+            return serializers.PrefixLengthSerializer
+        return super().get_serializer_class()
+
     @swagger_auto_schema(method='get', responses={200: serializers.AvailablePrefixSerializer(many=True)})
     @swagger_auto_schema(method='post', responses={201: serializers.AvailablePrefixSerializer(many=True)})
     @action(detail=True, url_path='available-prefixes', methods=['get', 'post'])


Test patch: