[Django] #25954: Properly set base field’s model recursively when nesting ArrayFields.

3 views
Skip to first unread message

Django

unread,
Dec 20, 2015, 6:07:24 AM12/20/15
to django-...@googlegroups.com
#25954: Properly set base field’s model recursively when nesting ArrayFields.
----------------------------------+---------------------------------------
Reporter: karanlyons | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.9
Severity: Normal | Keywords: ArrayField, from_db_value
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
----------------------------------+---------------------------------------
(My apologies if this turns out to be a bug in my head as opposed to a bug
in Django.)

ArrayField’s contribute_to_class() method of course doesn’t call the base
field’s contribute_to_class() but ''does'' set the model attribute. This
works perfectly when using a one dimensional array. It does not work with
nested arrays, however, as the model attribute is only ever set one level
deep. To whit:

{{{
ArrayField(models.CharField()) # Works fine.
ArrayField(ArrayField(models.CharField())) # AttributeError: 'CharField'
object has no attribute 'model'
}}}

This is easily fixed by checking if the base field is an instance of
ArrayField, and if so having it set model on its base field as well (and
do so recursively). I propose the attached patch in order to do so.

--
Ticket URL: <https://code.djangoproject.com/ticket/25954>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 20, 2015, 6:08:07 AM12/20/15
to django-...@googlegroups.com
#25954: Properly set base field’s model recursively when nesting ArrayFields.
---------------------------------------+----------------------------

Reporter: karanlyons | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution:

Keywords: ArrayField, from_db_value | Triage Stage: Unreviewed
Has patch: 1 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------+----------------------------
Changes (by karanlyons):

* Attachment "arrayfield_set_model_on_nested_arrayfields.diff" added.

Patch: Recursively set base field’s model to support nested ArrayFields.

Django

unread,
Dec 20, 2015, 6:34:47 AM12/20/15
to django-...@googlegroups.com
#25954: Properly set base field’s model recursively when nesting ArrayFields.
-------------------------------------+-------------------------------------
Reporter: karanlyons | Owner:
Type: Bug | Status: closed
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution: duplicate
Keywords: ArrayField, | Triage Stage:
from_db_value | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by karanlyons):

* status: new => closed
* needs_better_patch: => 0
* resolution: => duplicate
* needs_tests: => 0
* needs_docs: => 0


Comment:

Dupe of #25867.

--
Ticket URL: <https://code.djangoproject.com/ticket/25954#comment:1>

Reply all
Reply to author
Forward
0 new messages