﻿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
7551	GenericForeignKey fails if initialized to None during model init	Sam Bull	nobody	"Supposing you have a model with a GenericForeignKey...

{{{
#!python
class Example(models.Model):
    name = models.CharField()
    ct = models.ForeignKey(ContentType, null=True, blank=True)
    obj_id = models.PositiveIntegerField(null=True, blank=True)
    obj = GenericForeignKey()
}}}

If you initialize like this, everything is fine:
{{{
#!python
ex = Example(name='foobar')
}}}
But if you do this...
{{{
#!python
ex = Example(name='foobar', obj=None)
}}}
You get an exciting error:
{{{ Impossible arguments to GFK.get_content_type! }}}

It looks like the GFK tries to initialize the content_type and object_id fields if its attribute is one of the ones passed to the init. In fact, it should follow the example of __get__ and only initialize those fields if the argument passed to it is non-None."		new	Contrib apps	dev			contenttypes genericforeignkey		Unreviewed	1	0	0	0		
