Opened 8 years ago

Closed 8 years ago

#25954 closed Bug (duplicate)

Properly set base field’s model recursively when nesting ArrayFields.

Reported by: Karan Lyons Owned by:
Component: contrib.postgres Version: 1.9
Severity: Normal Keywords: ArrayField, from_db_value
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

(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.

Attachments (1)

arrayfield_set_model_on_nested_arrayfields.diff (636 bytes ) - added by Karan Lyons 8 years ago.
Patch: Recursively set base field’s model to support nested ArrayFields.

Download all attachments as: .zip

Change History (2)

by Karan Lyons, 8 years ago

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

comment:1 by Karan Lyons, 8 years ago

Resolution: duplicate
Status: newclosed

Dupe of #25867.

Note: See TracTickets for help on using tickets.
Back to Top