Repository: nautobot/nautobot

Issue:
Edit view for IPAM network objects does not emit the current network address value
<!--
    NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED.

    This form is only for reporting reproducible bugs. If you need assistance
    with Nautobot installation, or if you have a general question, please start a
    discussion instead: https://github.com/nautobot/nautobot/discussions

    Please describe the environment in which you are running Nautobot. 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: 3.8
* Nautobot version: 1.0.0b1 & b2

<!--
    Describe in detail the exact steps that someone else can take to reproduce
    this bug using the current stable release of Nautobot. 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 pynautobot.
-->
### Steps to Reproduce
1. Create an `IPAddress` in the UI
2. Edit it
3. :(

<!-- What did you expect to happen? -->
### Expected Behavior

The `address` field should be populated with the current value for that object.

<!-- What happened instead? -->
### Observed Behavior

The `address` field is blank in the edit view.

I compared this to `1.0.0b1` @ demo.autobot.com and `develop` running locally. I confirmed this to be true on `IPAddress.address`, `Prefix.prefix`, and `Aggregate.prefix`. It is 100% related to the varbinary field changes and these fields being converted from concrete to computed model fields. 


Discussion:

Resolving patch:
diff --git a/nautobot/ipam/forms.py b/nautobot/ipam/forms.py
--- a/nautobot/ipam/forms.py
+++ b/nautobot/ipam/forms.py
@@ -389,6 +389,7 @@ class Meta:
         ]
 
     def __init__(self, *args, **kwargs):
+
         super().__init__(*args, **kwargs)
 
         self.fields["vrf"].empty_label = "Global"
@@ -691,6 +692,8 @@ def __init__(self, *args, **kwargs):
                 elif type(nat_inside_parent) is VMInterface:
                     initial["nat_cluster"] = nat_inside_parent.virtual_machine.cluster.pk
                     initial["nat_virtual_machine"] = nat_inside_parent.virtual_machine.pk
+            # Address is a computed field, so it must be added to initial.
+            initial["address"] = instance.address
         kwargs["initial"] = initial
 
         super().__init__(*args, **kwargs)
diff --git a/nautobot/utilities/forms/forms.py b/nautobot/utilities/forms/forms.py
--- a/nautobot/utilities/forms/forms.py
+++ b/nautobot/utilities/forms/forms.py
@@ -130,6 +130,20 @@ class PrefixFieldMixin(forms.ModelForm):
 
     prefix = IPNetworkFormField()
 
+    def __init__(self, *args, **kwargs):
+
+        instance = kwargs.get("instance")
+        initial = kwargs.get("initial", {}).copy()
+
+        # If we're editing an object with a `prefix` field, we need to patch initial to include
+        # `prefix` because it is a computed field.
+        if instance is not None:
+            initial["prefix"] = instance.prefix
+
+        kwargs["initial"] = initial
+
+        super().__init__(*args, **kwargs)
+
     def save(self, *args, **kwargs):
         instance = super().save(commit=False)
         # call the model's prefix.setter method


Test patch: