Opened 13 years ago

Last modified 13 years ago

#16468 closed Bug

Django IPAddressField incorrectly casts values when querying — at Initial Version

Reported by: anonymous Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Django 1.3 running Postgres 9.0

I have a simple model with an IPAddressField. Before today my app only placed simple IP addresses into it (192.168.1.1 for example), but I expanded the functionality to accept ip ranges with CIDR notations (192.168.1.1/28 for example).

When I use django to get all records with an IP address which has a CIDR notation it issues the following SQL statement (abbreviated):
SELECT ..blah.. FROM "x" WHERE (HOST("x"."target") = E'192.168.1.1/28' )
This is comparing a HOST to a string, and it returns 0 results even though there are several entries in the database. It returns the correct results when I alter the query and run it through my postgresql shell:
SELECT ..blah.. FROM "x" WHERE (HOST("x"."target") = HOST('192.168.1.1/28') )

In short (at least on Postgresql) any data being compared against a IPAddressField should be cast to a HOST instead of a string.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top