From a1199d8528e2f51d333ea044a8b000665e2f7d7b Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Tue, 7 Nov 2006 05:01:35 +0000 Subject: [PATCH] Fixed #2894: XML deserializer now correctly handles null primary keys. git-svn-id: http://code.djangoproject.com/svn/django/trunk@4046 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/serializers/xml_serializer.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/django/core/serializers/xml_serializer.py b/django/core/serializers/xml_serializer.py index 09fff408cf..512b8c6176 100644 --- a/django/core/serializers/xml_serializer.py +++ b/django/core/serializers/xml_serializer.py @@ -166,7 +166,11 @@ class Deserializer(base.Deserializer): # If it doesn't exist, set the field to None (which might trigger # validation error, but that's expected). RelatedModel = self._get_model_from_node(node, "to") - return RelatedModel.objects.get(pk=getInnerText(node).strip().encode(self.encoding)) + # Check if there is a child node named 'None', returning None if so. + if len(node.childNodes) == 1 and node.childNodes[0].nodeName == 'None': + return None + else: + return RelatedModel.objects.get(pk=getInnerText(node).strip().encode(self.encoding)) def _handle_m2m_field_node(self, node): """