Reverting [7151]

8 views
Skip to first unread message

Jacob Kaplan-Moss

unread,
Feb 26, 2008, 4:08:57 PM2/26/08
to django-d...@googlegroups.com
Hey folks (and especially Malcom) --

So it looks like [7151] broke exact lookups for IP types in
PostgreSQL; this now fails::

>>> Model.objects.create(ip="10.0.0.1")
>>> Model.objects.get(ip="10.0.0.1")

You can see this in action in the failing serializers_regress unit
test (http://buildbot.djangoproject.com/trunk%202.5%20psycopg2/builds/338/step-test/0).

The problem is the casting -- ``CAST(ip AS text)`` returns something
of the form "10.0.0.1/32" (i.e. ip/netmask), which (obviously) doesn't
match the more simple IP.

Thus I'd like to revert [7151] until we can figure out a better fix
for substring searches. Any objections?

Jacob

Malcolm Tredinnick

unread,
Feb 26, 2008, 4:58:11 PM2/26/08
to django-d...@googlegroups.com

Whoops, my bad. Could have sworn I ran all the tests before committing.
Sorry about that. :-(

Definitely revert it. As noted in the ticket, I'm not 100% happy with
the solution anyway, for efficiency reasons, but this confirms that
doing the cast always is stupid.

We need to come up with a better solution for this stuff in general as
it comes up in a different form in #6605. I'm leaning towards doing a
cast based on both field type and lookup type for #6605. I think that
probably solves this problem as well: we only do the cast for the
particular lookup types (contains, icontains, etc).

Malcolm

--
Why can't you be a non-conformist like everyone else?
http://www.pointy-stick.com/blog/

Thomas K. Adamcik

unread,
Feb 26, 2008, 5:02:15 PM2/26/08
to django-d...@googlegroups.com

Hi there,

On Tue, Feb 26, 2008 at 03:08:57PM -0600, Jacob Kaplan-Moss wrote:
> The problem is the casting -- ``CAST(ip AS text)`` returns something
> of the form "10.0.0.1/32" (i.e. ip/netmask), which (obviously) doesn't
> match the more simple IP.

Like you said you don't want to use ``CAST(ip AS text)`` here, try using
``host(ip)`` and you should get the desired result.

http://www.postgresql.org/docs/8.2/static/functions-net.html has å nice
overview of the net related functions in PG :)

-Thomas

--
Thomas Kongevold Adamcik

Malcolm Tredinnick

unread,
Feb 26, 2008, 5:53:04 PM2/26/08
to django-d...@googlegroups.com

That's not really related to the issue at hand. It's overkill to have to
inspect a "contains" lookup to see if it's possible a host address and
then use host(ip), otherwise cast to a string for string-style lookups.
Anything that requires that level of deep introspection isn't really
practical via the standard lookups.

Malcolm

--
Monday is an awful way to spend 1/7th of your life.
http://www.pointy-stick.com/blog/

Malcolm Tredinnick

unread,
Feb 26, 2008, 5:54:25 PM2/26/08
to django-d...@googlegroups.com

On Wed, 2008-02-27 at 09:53 +1100, Malcolm Tredinnick wrote:
> On Tue, 2008-02-26 at 23:02 +0100, Thomas K. Adamcik wrote:
> >
> > Hi there,
> >
> > On Tue, Feb 26, 2008 at 03:08:57PM -0600, Jacob Kaplan-Moss wrote:
> > > The problem is the casting -- ``CAST(ip AS text)`` returns something
> > > of the form "10.0.0.1/32" (i.e. ip/netmask), which (obviously) doesn't
> > > match the more simple IP.
> >
> > Like you said you don't want to use ``CAST(ip AS text)`` here, try using
> > ``host(ip)`` and you should get the desired result.
> >
> > http://www.postgresql.org/docs/8.2/static/functions-net.html has å nice
> > overview of the net related functions in PG :)
> >
>
> That's not really related to the issue at hand.

Nope, I'm an idiot (again). You are correct.

Malcolm

--
Quantum mechanics: the dreams stuff is made of.
http://www.pointy-stick.com/blog/

Jacob Kaplan-Moss

unread,
Feb 26, 2008, 6:13:47 PM2/26/08
to django-d...@googlegroups.com
On 2/26/08, Thomas K. Adamcik <ada...@samfundet.no> wrote:
> Like you said you don't want to use ``CAST(ip AS text)`` here, try using
> ``host(ip)`` and you should get the desired result.

Ah, that's it -- thanks! Committed in [7161].

Jacob

Reply all
Reply to author
Forward
0 new messages