[Django] #25143: ArrayField should implement from_db_value()

29 views
Skip to first unread message

Django

unread,
Jul 19, 2015, 12:45:12 AM7/19/15
to django-...@googlegroups.com
#25143: ArrayField should implement from_db_value()
----------------------------------+-----------------
Reporter: Odahi | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+-----------------
I'm using a custom field with the new Postgres {{{ArrayField}}}:


{{{

class Tag(object):
def __init__(self, id):
self.id = id

def __unicode__(self):
return U"Tag(%d)" % self.id


class TagField(models.SmallIntegerField):
# Dummy wrapper over SmallIntegerField.

def from_db_value(self, value, expression, connection, context):
if value is None:
return value
return Tag(int(value))

def get_prep_value(self, value):
return value
...

# models.py

class Recommendation(models.Model):
tags = ArrayField(TagField(), size=3)

def __unicode__(self):
return self.tags
}}}


Then


{{{
>>> Recommendation.objects.create(tags=[Tag(1), Tag(2)])
>>> Recommendation.objects.all()

[<Recommendation: [1, 2]>] # WRONG

}}}

But this is wrong because I got Integers instead of Tag objects:

{{{
[<Recommendation: [Tag(1), Tag(2)]>] # OK
}}}

Looking at the {{{ArrayField}}} source code seems that {{{to_python()}}}
is implemented but never called. I think {{{from_db_value()}}} should be
also implemented.

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

Django

unread,
Jul 19, 2015, 11:23:15 AM7/19/15
to django-...@googlegroups.com
#25143: ArrayField should implement from_db_value()
----------------------------------+--------------------------------------

Reporter: Odahi | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Old description:

> Then
>

New description:

I'm using a custom field with the new Postgres {{{ArrayField}}}:


{{{

class Tag(object):
def __init__(self, id):
self.id = id

def __unicode__(self):
return U"Tag(%d)" % self.id


class TagField(models.SmallIntegerField):
# Dummy wrapper over SmallIntegerField.

def from_db_value(self, value, expression, connection, context):
if value is None:
return value
return Tag(int(value))

def get_prep_value(self, value):
return value
...

# models.py

class Recommendation(models.Model):
tags = ArrayField(TagField(), size=3)

def __unicode__(self):
return self.tags
}}}


Then


{{{
>>> Recommendation.objects.create(tags=[Tag(1), Tag(2)])
>>> Recommendation.objects.all()

[<Recommendation: [1, 2]>] # WRONG

}}}

This is wrong because I got Integers instead of Tag objects:

{{{
[<Recommendation: [Tag(1), Tag(2)]>] # OK
}}}

Looking at the {{{ArrayField}}} source code seems that {{{to_python()}}}
is implemented but never called. I think {{{from_db_value()}}} should be
also implemented.

--

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

Django

unread,
Jul 20, 2015, 6:20:05 PM7/20/15
to django-...@googlegroups.com
#25143: ArrayField should implement from_db_value()
----------------------------------+--------------------------------------

Reporter: Odahi | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

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

Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by timgraham):

Can you propose a patch and regression test?

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

Django

unread,
Jul 20, 2015, 11:30:06 PM7/20/15
to django-...@googlegroups.com
#25143: ArrayField should implement from_db_value()
----------------------------------+--------------------------------------

Reporter: Odahi | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

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

Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Odahi):

Replying to [comment:2 timgraham]:


> Can you propose a patch and regression test?


Hello Tim, never did it before, but I think I can submit a tentative patch
& test for this in the next days. I'll try.

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

Django

unread,
Jul 22, 2015, 2:02:43 PM7/22/15
to django-...@googlegroups.com
#25143: ArrayField should implement from_db_value()
----------------------------------+--------------------------------------

Reporter: Odahi | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* has_patch: 0 => 1


Comment:

I've just added a tentative patch.
https://github.com/Odahi/django/tree/ticket_25143
Would be great if someone can check it.

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

Django

unread,
Jul 28, 2015, 1:12:32 PM7/28/15
to django-...@googlegroups.com
#25143: ArrayField should implement from_db_value()
----------------------------------+------------------------------------

Reporter: Odahi | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

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

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

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/25143#comment:5>

Django

unread,
Sep 10, 2015, 7:30:51 AM9/10/15
to django-...@googlegroups.com
#25143: ArrayField should implement from_db_value()
----------------------------------+------------------------------------

Reporter: Odahi | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25143#comment:6>

Django

unread,
Oct 21, 2015, 6:43:39 PM10/21/15
to django-...@googlegroups.com
#25143: ArrayField should implement from_db_value()
----------------------------------+------------------------------------

Reporter: Odahi | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------

Comment (by timgraham):

See #25579 for a related issue (querying on complex types) that could be
fixed along with this.

--
Ticket URL: <https://code.djangoproject.com/ticket/25143#comment:7>

Django

unread,
Feb 12, 2016, 5:41:52 PM2/12/16
to django-...@googlegroups.com
#25143: ArrayField should implement from_db_value()
----------------------------------+------------------------------------

Reporter: Odahi | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: 1 => 0


Comment:

[https://github.com/django/django/pull/6131 Updated PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/25143#comment:8>

Django

unread,
Feb 13, 2016, 7:24:42 AM2/13/16
to django-...@googlegroups.com
#25143: ArrayField should implement from_db_value()
-------------------------------------+-------------------------------------

Reporter: Odahi | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

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

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

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/25143#comment:9>

Django

unread,
Feb 17, 2016, 8:57:36 PM2/17/16
to django-...@googlegroups.com
#25143: ArrayField should implement from_db_value()
----------------------------------+------------------------------------

Reporter: Odahi | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/25143#comment:10>

Django

unread,
Mar 12, 2016, 9:33:32 AM3/12/16
to django-...@googlegroups.com
#25143: ArrayField should implement from_db_value()
-------------------------------------+-------------------------------------
Reporter: Odahi | Owner: Tim
| Graham <timograham@…>
Type: Bug | Status: closed
Component: contrib.postgres | Version: 1.8
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* owner: => Tim Graham <timograham@…>
* resolution: => fixed


Comment:

In [changeset:"2495023a4cae28f494d0a6172abfac3a47a0b816" 2495023]:
{{{
#!CommitTicketReference repository=""
revision="2495023a4cae28f494d0a6172abfac3a47a0b816"
Fixed #25143 -- Added ArrayField.from_db_value().

Thanks Karan Lyons for contributing to the patch.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25143#comment:11>

Reply all
Reply to author
Forward
0 new messages