Repository: nautobot/nautobot

Issue:
Change maximum allowed value for Integer Type in Custom Fields
<!--
    NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED.

    This form is only for proposing specific new features or enhancements.
    If you have a general idea or question, please start a discussion instead:
    https://github.com/nautobot/nautobot/discussions

    Please describe the environment in which you are running Nautobot.
-->
### Environment
* Python version: 3.9.1
* Nautobot version: v1.0.2

<!--
    Describe in detail the new functionality you are proposing. Include any
    specific changes to work flows, data models, or the user interface.
-->
### Proposed Functionality
The maximum value of an Integer used in a CustomField should be bigger than 2147483647.

<!--
    Convey an example use case for your proposed feature. Write from the
    perspective of a Nautobot user who would benefit from the proposed
    functionality and describe how.
--->
### Use Case
I'd like to have a custom field ASN, which by nature needs to go up to 4294967294.

<!--
    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
Unknown

<!--
    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
None


Discussion:
Hmmm great idea. This would likely be as "simple" as changing `CustomField.validation_minimum/validation_maximum` fields from `PositiveIntegerField` types to [`PositiveBigIntegerField`](https://docs.djangoproject.com/en/3.2/ref/models/fields/#positivebigintegerfield). Of course we'd still have to account for testing, and to make sure that the schema migration for the field type also includes a data migration. Because of this, we likely wouldn't be able to implement this until v1.2 at the earliest.
I can work on this.
@Joezeppe thanks Sammy, go for it!

Resolving patch:
diff --git a/nautobot/extras/migrations/0010_change_cf_validation_max_min_field_to_bigint.py b/nautobot/extras/migrations/0010_change_cf_validation_max_min_field_to_bigint.py
new file mode 100644
--- /dev/null
+++ b/nautobot/extras/migrations/0010_change_cf_validation_max_min_field_to_bigint.py
@@ -0,0 +1,23 @@
+# Generated by Django 3.1.13 on 2021-07-02 22:49
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("extras", "0009_computedfield"),
+    ]
+
+    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/nautobot/extras/models/customfields.py b/nautobot/extras/models/customfields.py
--- a/nautobot/extras/models/customfields.py
+++ b/nautobot/extras/models/customfields.py
@@ -224,13 +224,13 @@ class CustomField(BaseModel):
     weight = models.PositiveSmallIntegerField(
         default=100, help_text="Fields with higher weights appear lower in a form."
     )
-    validation_minimum = models.PositiveIntegerField(
+    validation_minimum = models.BigIntegerField(
         blank=True,
         null=True,
         verbose_name="Minimum value",
         help_text="Minimum allowed value (for numeric fields)",
     )
-    validation_maximum = models.PositiveIntegerField(
+    validation_maximum = models.BigIntegerField(
         blank=True,
         null=True,
         verbose_name="Maximum value",


Test patch:
diff --git a/nautobot/extras/tests/test_customfields.py b/nautobot/extras/tests/test_customfields.py
--- a/nautobot/extras/tests/test_customfields.py
+++ b/nautobot/extras/tests/test_customfields.py
@@ -565,6 +565,36 @@ def test_minimum_maximum_values_validation(self):
         response = self.client.patch(url, data, format="json", **self.header)
         self.assertHttpStatus(response, status.HTTP_200_OK)
 
+    def test_bigint_values_of_custom_field_maximum_attribute(self):
+        url = reverse("dcim-api:site-detail", kwargs={"pk": self.sites[1].pk})
+        self.add_permissions("dcim.change_site")
+
+        self.cf_integer.validation_maximum = 5000000000
+        self.cf_integer.save()
+
+        data = {"custom_fields": {"number_field": 4294967294}}
+        response = self.client.patch(url, data, format="json", **self.header)
+        self.assertHttpStatus(response, status.HTTP_200_OK)
+
+        data = {"custom_fields": {"number_field": 5000000001}}
+        response = self.client.patch(url, data, format="json", **self.header)
+        self.assertHttpStatus(response, status.HTTP_400_BAD_REQUEST)
+
+    def test_bigint_values_of_custom_field_minimum_attribute(self):
+        url = reverse("dcim-api:site-detail", kwargs={"pk": self.sites[1].pk})
+        self.add_permissions("dcim.change_site")
+
+        self.cf_integer.validation_minimum = -5000000000
+        self.cf_integer.save()
+
+        data = {"custom_fields": {"number_field": -4294967294}}
+        response = self.client.patch(url, data, format="json", **self.header)
+        self.assertHttpStatus(response, status.HTTP_200_OK)
+
+        data = {"custom_fields": {"number_field": -5000000001}}
+        response = self.client.patch(url, data, format="json", **self.header)
+        self.assertHttpStatus(response, status.HTTP_400_BAD_REQUEST)
+
     def test_regex_validation(self):
         url = reverse("dcim-api:site-detail", kwargs={"pk": self.sites[1].pk})
         self.add_permissions("dcim.change_site")