﻿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
14325	GenericForeignKey fails if assigned to an object which implements the __len__ method	Martin Natano	Martin Natano	"Supposing you have a model with a GenericForeignKey:
{{{
class Example(models.Model):
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    instance = generic.GenericForeignKey()
}}}

and a model which implements the {{{__len__}}} method:
{{{
class Table(models.Model)
    data = models.TextField()

    def __len__(self):
        return 0
}}}

If you do
{{{
t = Table.object.create()
e = Example()
e.instance = t
}}}
you get an error:
{{{
Impossible arguments to GFK.get_content_type!
}}}

I think this is cause by checking for a logical True value instead of a ""not None"" comparison.
"	Bug	closed	contrib.contenttypes	1.2	Normal	duplicate	contenttypes, genericforeignkey	natano@…	Accepted	1	0	1	0	0	0
