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

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
Contributor

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

tests/generic_relations/models.py
@@ -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

timgraham Oct 15, 2013

Owner

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

@Bouke

Bouke Oct 15, 2013

Contributor

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

tests/generic_relations/tests.py
@@ -440,3 +440,20 @@ def test_generic_relation_set(self):
newrel.bases = [base]
newrel = ConcreteRelatedModel.objects.get(pk=newrel.pk)
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

timgraham Oct 15, 2013

Owner

use with six.assertRaisesRegex(self, ...

Owner

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