[Django] #25953: Add from_db_value() support to django.contrib.postgres.fields.ArrayField.

4 views
Skip to first unread message

Django

unread,
Dec 20, 2015, 2:06:38 AM12/20/15
to django-...@googlegroups.com
#25953: Add from_db_value() support to django.contrib.postgres.fields.ArrayField.
----------------------------------+---------------------------------------
Reporter: karanlyons | Owner:
Type: New feature | 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
----------------------------------+---------------------------------------
Currently ArrayField assumes that the base field will not need to alter
the returned python value from the postgres backend, as this is the case
for all core fields. As an example, take this absurd field:

{{{
class ContrivedStringedIntegerField(models.IntegerField):
def from_db_value(self, value, expression, connection, context):
return unicode(value)
}}}

Used alone in a model this will return a string, but used as part of an
ArrayField we’ll get integers instead.

from_db_value() is a no-op for performance reasons, so rather than incur
the penalty inside of ArrayField when it’s unnecessary, I propose the
attached patch, which adds a from_db_value() method to the instantiated
ArrayField if its base field has one as well.

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

Django

unread,
Dec 20, 2015, 2:07:09 AM12/20/15
to django-...@googlegroups.com
#25953: Add from_db_value() support to django.contrib.postgres.fields.ArrayField.
---------------------------------------+----------------------------

Reporter: karanlyons | Owner:
Type: New feature | 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_condtionally_add_from_db_value.diff" added.

Patch: Conditionally add from_db_value() to ArrayField instances.

Django

unread,
Dec 20, 2015, 2:08:38 AM12/20/15
to django-...@googlegroups.com
#25953: Add from_db_value() support to django.contrib.postgres.fields.ArrayField.
-------------------------------------+-------------------------------------
Reporter: karanlyons | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution:
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):

* needs_better_patch: => 0
* type: New feature => Bug
* needs_tests: => 0
* needs_docs: => 0


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

Django

unread,
Dec 20, 2015, 12:05:06 PM12/20/15
to django-...@googlegroups.com
#25953: Add from_db_value() support to django.contrib.postgres.fields.ArrayField.
-------------------------------------+-------------------------------------
Reporter: karanlyons | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: ArrayField, | Triage Stage: Accepted
from_db_value |

Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

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

* version: 1.9 => master
* needs_tests: 0 => 1
* stage: Unreviewed => Accepted


Comment:

Makes sense to me but this will need additional tests to get merged.

If you could submit your patch as Github PR it would also give it more
visibility and help reviewers run CI against it.

Concerning the implementation I think you should avoid creating a local
function to attach it as a method but declare a `_from_db_value` method
that you assign to `from_db_value` instead.

--
Ticket URL: <https://code.djangoproject.com/ticket/25953#comment:2>

Django

unread,
Dec 20, 2015, 12:05:36 PM12/20/15
to django-...@googlegroups.com
#25953: Add from_db_value() support to django.contrib.postgres.fields.ArrayField.
-------------------------------------+-------------------------------------
Reporter: karanlyons | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.9

Severity: Normal | Resolution:
Keywords: ArrayField, | Triage Stage: Accepted
from_db_value |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* version: master => 1.9


--
Ticket URL: <https://code.djangoproject.com/ticket/25953#comment:3>

Django

unread,
Dec 20, 2015, 12:26:24 PM12/20/15
to django-...@googlegroups.com
#25953: Add from_db_value() support to django.contrib.postgres.fields.ArrayField.
-------------------------------------+-------------------------------------
Reporter: karanlyons | Owner:
Type: Bug | Status: closed
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution: duplicate

Keywords: ArrayField, | Triage Stage: Accepted
from_db_value |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #25143

--
Ticket URL: <https://code.djangoproject.com/ticket/25953#comment:4>

Reply all
Reply to author
Forward
0 new messages