{{{
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.
* 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>
* owner: => mjtamlyn
* status: new => assigned
* has_patch: 0 => 1
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24092#comment:2>
* severity: Normal => Release blocker
--
Ticket URL: <https://code.djangoproject.com/ticket/24092#comment:3>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/24092#comment:4>
* 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>