﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
16055	Filtering over generic relations with TextField/CharField object_id breaks in postgres	anonymous	David Wobrock	"When you have a generic foreign key with TextField / CharField object_id, and try to use it in a filter with a model that has an integer primary key, PostgreSQL 9.0.4 errors out with this:
{{{
DatabaseError: operator does not exist: integer = text

HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
}}}

A small example:
{{{
class Tag(models.Model):
    tag = models.SlugField()
    content_type = models.ForeignKey(ContentType)
    object_id = models.TextField()
    content_object = generic.GenericForeignKey()

class Animal(models.Model):
    name = models.TextField()
    tags = generic.GenericRelation(Tag)

print Animal.objects.filter(tags__tag='mammal')
}}}

I have a patch that changes Django's generic foreign key tests to also try everything with a textual object_id, which exhibits this problem.

A workaround is to create this cast as implicit in postgres:
{{{
CREATE CAST (integer AS text) WITH INOUT AS IMPLICIT
}}}"	Bug	closed	contrib.contenttypes	3.2	Normal	fixed		victor.van.den.elzen@… joeri@… mmitar@… brian@… Kye Russell Kevin Wiliarty Marc DEBUREAUX Sage Abdullah David Wobrock	Ready for checkin	1	0	0	0	0	0
