{{{
class Foo(models.Model):
bar = ArrayField(models.CharField(...))
}}}
And create a `ModelForm`:
{{{
FooForm = modelform_factory(Foo, excludes=[])
}}}
The field will fail with already-converted values, like
{{{
foo = Foo.objects.create(bar=['a', 'b'])
data = model_to_dict(foo) # {'bar': ['a', 'b']}
form = FooForm(instance=foo, data=data)
form.full_clean() # errors at django/contrib/postgres/forms/array.py:39
}}}
Shouldn't already converted values be checked in the `to_python` method of
`ArrayField`? (Same with `JSONField`)
--
Ticket URL: <https://code.djangoproject.com/ticket/27003>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* has_patch: 0 => 1
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/27003#comment:1>
Comment (by brandonchinn178):
Fixed in pull request: https://github.com/django/django/pull/7012
--
Ticket URL: <https://code.djangoproject.com/ticket/27003#comment:2>
Comment (by claudep):
I think the solution you proposed in your patch is good for ArrayField,
but it might be more tricky for JSONField as a string can be both a
converted and an unconverted value, so the isinstance is not covering all
cases (see #25532).
--
Ticket URL: <https://code.djangoproject.com/ticket/27003#comment:3>
* needs_better_patch: 0 => 1
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/27003#comment:4>
Comment (by brandonchinn178):
For JSONField, what about making a custom `six.text_type` for converted
strings, like #25532:
{{{
class JsonStr(six.text_type):
pass
def to_python(self, value):
...
if isinstance(value, JsonStr):
return value
val = json.loads(value)
# parse val and convert all strings to JsonStr
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27003#comment:5>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/27003#comment:6>
* owner: nobody => MaartenPI
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/27003#comment:7>
* status: assigned => new
* owner: MaartenPI => (none)
--
Ticket URL: <https://code.djangoproject.com/ticket/27003#comment:8>
* owner: (none) => mr-bo-jangles
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/27003#comment:9>
* owner: mr-bo-jangles => (none)
* status: assigned => new
* stage: Accepted => Ready for checkin
Comment:
Work is all done, just needs a minor change to the name of the type used,
however I can't edit this PR, only the merged code so I've removed myself
from this ticket.
--
Ticket URL: <https://code.djangoproject.com/ticket/27003#comment:10>
* version: 1.10 => master
* stage: Ready for checkin => Accepted
Comment:
Please don't mark your own patch as RFC. See our contributing guidelines
for more details.
[https://github.com/django/django/pull/7488 PR].
--
Ticket URL: <https://code.djangoproject.com/ticket/27003#comment:11>
* cc: emad.m.habib@… (added)
* stage: Accepted => Ready for checkin
Comment:
I ran the tests with changes nothing failed and ran the same tests without
changes and it failed.
Note: I ran tests using PostgreSQL 9.3
--
Ticket URL: <https://code.djangoproject.com/ticket/27003#comment:12>
Comment (by Tim Graham <timograham@…>):
In [changeset:"6573274161ee589e89077192239e0bd01cbd692a" 6573274]:
{{{
#!CommitTicketReference repository=""
revision="6573274161ee589e89077192239e0bd01cbd692a"
Refs #27003 -- Fixed SimpleArrayField crash on converted values.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27003#comment:13>
Comment (by Tim Graham <timograham@…>):
In [changeset:"eed615000903ec7b659c3563b7b4b4b3f34f5636" eed61500]:
{{{
#!CommitTicketReference repository=""
revision="eed615000903ec7b659c3563b7b4b4b3f34f5636"
Refs #27003 -- Fixed JSONField crash on converted values.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27003#comment:14>
* status: new => closed
* resolution: => fixed
--
Ticket URL: <https://code.djangoproject.com/ticket/27003#comment:15>