From 20c69c5e51f1ca180978a51d64246b70f778df83 Mon Sep 17 00:00:00 2001 From: Karen Tracey Date: Mon, 12 Mar 2012 19:41:31 +0000 Subject: 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 --- django/core/serializers/python.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'django/core/serializers/python.py') 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 -- cgit v1.3