[Django] #24092: New ArrayField from django.contrib.postgres.fields does not correctly save an array of GenericIPAddressField

27 views
Skip to first unread message

Django

unread,
Jan 7, 2015, 12:13:57 PM1/7/15
to django-...@googlegroups.com
#24092: New ArrayField from django.contrib.postgres.fields does not correctly save
an array of GenericIPAddressField
----------------------------------+--------------------
Reporter: smclenithan | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------
ArrayField throws an error when using an array of GenericIPAddressField as
the base_field:

{{{
from django.contrib.postgres.fields import ArrayField

class MyModel(models.Model):
ips = ArrayField(base_field=models.GenericIPAddressField(),
db_index=True)
}}}

{{{
>>> test = MyModel()
>>> test.ips = ['10.2.3.4', '1.2.3.4']
>>> test.save()

... truncated...

django.db.utils.ProgrammingError: column "ips" is of type inet[] but
expression is of type text[]
LINE 1: ...story" SET "model_id" = 1, "ips" = ARRAY['10...
}}}

There also appears to be an issue, when reading from the model (where
inet[] data was set in the db itself), instead of a string array of IPs
being returned we get this:
{{{
>>> test.ips
'{10.2.3.4, 1.2.3.4}'
}}}

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

Django

unread,
Jan 7, 2015, 5:26:44 PM1/7/15
to django-...@googlegroups.com
#24092: New ArrayField from django.contrib.postgres.fields does not correctly save
an array of GenericIPAddressField
----------------------------------+--------------------------------------

Reporter: smclenithan | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: master
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 jarshwah):

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


Comment:

Would a cast(x as inet) for each element resolve this? Also, UUID is
similar to inet (text value with specific type) so it may also be
affected.

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

Django

unread,
Jan 10, 2015, 1:13:57 PM1/10/15
to django-...@googlegroups.com
#24092: New ArrayField from django.contrib.postgres.fields does not correctly save
an array of GenericIPAddressField
----------------------------------+------------------------------------
Reporter: smclenithan | Owner: mjtamlyn
Type: Bug | Status: assigned
Component: contrib.postgres | Version: master
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 mjtamlyn):

* owner: => mjtamlyn
* status: new => assigned
* has_patch: 0 => 1
* stage: Unreviewed => Accepted


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

Django

unread,
Jan 12, 2015, 3:47:46 AM1/12/15
to django-...@googlegroups.com
#24092: New ArrayField from django.contrib.postgres.fields does not correctly save
an array of GenericIPAddressField
----------------------------------+------------------------------------
Reporter: smclenithan | Owner: mjtamlyn
Type: Bug | Status: assigned
Component: contrib.postgres | Version: master
Severity: Release blocker | 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 mjtamlyn):

* severity: Normal => Release blocker


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

Django

unread,
Jan 12, 2015, 8:38:29 AM1/12/15
to django-...@googlegroups.com
#24092: New ArrayField from django.contrib.postgres.fields does not correctly save
an array of GenericIPAddressField
-------------------------------------+-------------------------------------

Reporter: smclenithan | Owner: mjtamlyn
Type: Bug | Status: assigned
Component: contrib.postgres | Version: master
Severity: Release blocker | 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/24092#comment:4>

Django

unread,
Jan 16, 2015, 4:16:19 PM1/16/15
to django-...@googlegroups.com
#24092: New ArrayField from django.contrib.postgres.fields does not correctly save
an array of GenericIPAddressField
-------------------------------------+-------------------------------------
Reporter: smclenithan | Owner: mjtamlyn
Type: Bug | Status: closed
Component: contrib.postgres | Version: master
Severity: Release blocker | Resolution: fixed

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 Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"39d95fb6ada99c59d47fa0eae6d3128abafe2d58"]:
{{{
#!CommitTicketReference repository=""
revision="39d95fb6ada99c59d47fa0eae6d3128abafe2d58"
Fixed #24092 -- Widened base field support for ArrayField.

Several issues resolved here, following from a report that a base_field
of GenericIpAddressField was failing.

We were using get_prep_value instead of get_db_prep_value in ArrayField
which was bypassing any extra modifications to the value being made in
the base field's get_db_prep_value. Changing this broke datetime
support, so the postgres backend has gained the relevant operation
methods to send dates/times/datetimes directly to the db backend instead
of casting them to strings. Similarly, a new database feature has been
added allowing the uuid to be passed directly to the backend, as we do
with timedeltas.

On the other side, psycopg2 expects an Inet() instance for IP address
fields, so we add a value_to_db_ipaddress method to wrap the strings on
postgres. We also have to manually add a database adapter to psycopg2,
as we do not wish to use the built in adapter which would turn
everything into Inet() instances.

Thanks to smclenithan for the report.
}}}

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

Reply all
Reply to author
Forward
0 new messages