Opened 10 years ago
Closed 10 years ago
#24092 closed Bug (fixed)
New ArrayField from django.contrib.postgres.fields does not correctly save an array of GenericIPAddressField
Reported by: | Steve | Owned by: | Marc Tamlyn |
---|---|---|---|
Component: | contrib.postgres | Version: | dev |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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}'
Change History (5)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
Has patch: | set |
---|---|
Owner: | set to |
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 10 years ago
Severity: | Normal → Release blocker |
---|
comment:4 by , 10 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:5 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
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.