Fixed #7551 -- GFK should allow None init argument #1753

wants to merge 1 commit into


None yet
2 participants

Bouke commented Oct 15, 2013

See ticket #7551. Currently GFK raises an exception when None is passed as initializing argument. Normal FK's allow None, so there is a discrepancy. This fix solves both the cases of required and non-required GFK initializing.

@timgraham timgraham and 1 other commented on an outdated diff Oct 15, 2013

@@ -137,3 +137,10 @@ class ConcreteRelatedModel(models.Model):
class ProxyRelatedModel(ConcreteRelatedModel):
class Meta:
proxy = True
+# To test fix for #7551
+class Paper(models.Model):

timgraham Oct 15, 2013


would be helpful to choose a more meaningful model name, something like "AllowsNullGFK"?


Bouke Oct 15, 2013


Sure, although my inspiration came from the other model names in that file (Gecko, Vegetable, Rock). But fair enough, will change it.

@timgraham timgraham commented on an outdated diff Oct 15, 2013

@@ -440,3 +440,20 @@ def test_generic_relation_set(self):
newrel.bases = [base]
newrel = ConcreteRelatedModel.objects.get(
self.assertEqual(base, newrel.bases.get())
+class TestInitWithNoneArgument(TestCase):
+ def test_none_not_allowed(self):
+ # TaggedItem requires a content_type, initializing with None should
+ # raise a ValueError.
+ self.assertRaisesRegexp(

timgraham Oct 15, 2013


use with six.assertRaisesRegex(self, ...


timgraham commented Oct 16, 2013

thanks for the updates. I just changed assertRaisesRegex to use a context manager as I find that syntax a bit clearer. merged in 3918eeb.

timgraham closed this Oct 16, 2013

Bouke deleted the Bouke:ticket_7551 branch Oct 17, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment