#16468: Django IPAddressField incorrectly casts values when querying
-------------------------------------+-------------------------------------
     Reporter:  anonymous            |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  1.3
  (models, ORM)                      |               Resolution:  wontfix
     Severity:  Normal               |             Triage Stage:  Design
     Keywords:                       |  decision needed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by ramiro:

Old 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.

New 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.

--

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to