summaryrefslogtreecommitdiff
path: root/django/core/serializers/python.py
diff options
context:
space:
mode:
authorKaren Tracey <kmtracey@gmail.com>2012-03-12 19:41:31 +0000
committerKaren Tracey <kmtracey@gmail.com>2012-03-12 19:41:31 +0000
commit20c69c5e51f1ca180978a51d64246b70f778df83 (patch)
tree3474f89cb721848291e2eda3f4d7aa66639aa93e /django/core/serializers/python.py
parent2f520139bedffc8622d8c598443c90d58f6a427e (diff)
Fix #17879: Corrected regression in python (inherited by yaml and json) serializer that prevented serializing model instances with null FK ref to a model when serializing with natural keys. Thanks danfairs and tmitchell.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17685 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core/serializers/python.py')
-rw-r--r--django/core/serializers/python.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/django/core/serializers/python.py b/django/core/serializers/python.py
index 6cdfc9f240..195bf11d24 100644
--- a/django/core/serializers/python.py
+++ b/django/core/serializers/python.py
@@ -47,7 +47,10 @@ class Serializer(base.Serializer):
def handle_fk_field(self, obj, field):
if self.use_natural_keys and hasattr(field.rel.to, 'natural_key'):
related = getattr(obj, field.name)
- value = related.natural_key()
+ if related:
+ value = related.natural_key()
+ else:
+ value = None
else:
value = getattr(obj, field.get_attname())
self._current[field.name] = value