summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorRamiro Morales <cramm0@gmail.com>2013-02-05 23:35:10 -0300
committerRamiro Morales <cramm0@gmail.com>2013-02-07 16:05:54 -0300
commit04d9730b127c689b8eda01cbc913efa6e2eb230b (patch)
tree5ff07b85c9a3b5e192fc9abfb537701d30593fd7 /django
parent2b916895a1cea39de3280a6910e2886aebfcfc64 (diff)
Fixed #13085 -- Don't fail on creation of model with GFK to a model with __len__() returning zero.
Also, according to the comments on the ticket and its duplicates, added tests execising saving an instance of a model with a GFK to: * An unsaved object -- This actually doesn't generate the same failure but another ORM-level exception. The test verifies it's the case. * An instance of a model with a __nonzero__() method thant returns False for it. This doesn't fail because that code path isn't executed. * An instance of a model with a CharField PK and an empty value for it. This doesn't fail.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/contenttypes/generic.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py
index d849d1607e..20ff7042bc 100644
--- a/django/contrib/contenttypes/generic.py
+++ b/django/contrib/contenttypes/generic.py
@@ -43,7 +43,7 @@ class GenericForeignKey(object):
def instance_pre_init(self, signal, sender, args, kwargs, **_kwargs):
"""
- Handles initializing an object with the generic FK instaed of
+ Handles initializing an object with the generic FK instead of
content-type/object-id fields.
"""
if self.name in kwargs:
@@ -52,7 +52,7 @@ class GenericForeignKey(object):
kwargs[self.fk_field] = value._get_pk_val()
def get_content_type(self, obj=None, id=None, using=None):
- if obj:
+ if obj is not None:
return ContentType.objects.db_manager(obj._state.db).get_for_model(obj)
elif id:
return ContentType.objects.db_manager(using).get_for_id(id)