The issue is similar to this bug that has been fixed:
https://code.djangoproject.com/ticket/24428 however doesn't seem to be due
to coercion. I've discovered this when trying to update a project from
django 2.2 to 3.2

test case to reproduce (in a new django project/app)

```
from django.db import models
from django.forms import ModelForm


class Vehicle(models.Model):
    modifications = models.JSONField(default=list, blank=True, null=True)


class VehicleForm(ModelForm):
    class Meta:
        model = Vehicle
        fields = ("modifications", )


def test_vehicle_form():
    vehicle = Vehicle.objects.create()
    assert vehicle.modifications == []
    data = {"modifications": "[]"}
    form = VehicleForm(data, instance=vehicle)
    assert form.is_valid()
    assert not form.has_changed()
```

I would expect that test to pass, but it doesn't. I'm not sure exactly
where the error lies, but I have discovered the following:

```
field.show_hidden_initial == True
field.to_python(hidden_widget.value_from_datadict(self.data, self.files,
initial_prefixed_name)) == None
```
which then fails the check in field.has_changed
```
initial_value = initial if initial is not None else ''
data_value = data if data is not None else ''
return initial_value != data_value
```
because `data == []`

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFy-P0f5xB-CHiSSO50KAHmHNn6ha5nUEO-coOPj67zAZ00qhg%40mail.gmail.com.

Reply via email to