The following small code example will demonstrate the issue by failing on
the last assert.
{{{
from django.db import models
from django import forms
from django.contrib.postgres.fields import ArrayField
class TestModel(models.Model):
array = ArrayField(models.CharField(max_length=10), default=list,
blank=True)
class Meta:
app_label = 'test'
class TestForm(forms.ModelForm):
array = forms.MultipleChoiceField(choices=(('one', 'One'), ('two',
'Two')), required=False)
class Meta:
model = TestModel
fields = '__all__'
test_instance = TestModel(array=['one'])
assert test_instance.array == ['one']
test_form = TestForm(instance=test_instance)
test_form = TestForm(data=[], instance=test_instance)
assert test_form.is_valid()
assert test_form.cleaned_data == {'array': []}
updated_instance = test_form.save(commit=False)
assert updated_instance.array == []
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27993>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* stage: Unreviewed => Accepted
Comment:
The fix is to add `SelectMultiple.value_omitted_from_data()` that always
returns `False`, similar to 87c5e7efebd040aef0f0479ccf86877155bb5cea.
--
Ticket URL: <https://code.djangoproject.com/ticket/27993#comment:1>
* status: new => assigned
* owner: nobody => heathervm
--
Ticket URL: <https://code.djangoproject.com/ticket/27993#comment:2>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/8266 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/27993#comment:3>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"7d1e23775344cc3dead03bd4af45f4fdf134b819" 7d1e237]:
{{{
#!CommitTicketReference repository=""
revision="7d1e23775344cc3dead03bd4af45f4fdf134b819"
Fixed #27993 -- Fixed model form default fallback for SelectMultiple.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27993#comment:4>
Comment (by Tim Graham <timograham@…>):
In [changeset:"ff0c6b83e590e36555639563c4bd1d808f416455" ff0c6b83]:
{{{
#!CommitTicketReference repository=""
revision="ff0c6b83e590e36555639563c4bd1d808f416455"
[1.11.x] Fixed #27993 -- Fixed model form default fallback for
SelectMultiple.
Backport of 7d1e23775344cc3dead03bd4af45f4fdf134b819 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27993#comment:5>
Comment (by Tim Graham <timograham@…>):
In [changeset:"83331d1ed0fde144767e8f35f2d9e512bdd2afb1" 83331d1]:
{{{
#!CommitTicketReference repository=""
revision="83331d1ed0fde144767e8f35f2d9e512bdd2afb1"
[1.10.x] Fixed #27993 -- Fixed model form default fallback for
SelectMultiple.
Backport of 7d1e23775344cc3dead03bd4af45f4fdf134b819 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27993#comment:6>