From 9f59fc5560ae4ae1d6b73996393caae2314fd414 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Thu, 28 Aug 2008 19:38:56 +0000 Subject: [PATCH] Fixed #8651: correctly deserialize objects with 0 for pk/fk. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8676 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/serializers/python.py | 2 +- tests/regressiontests/serializers_regress/tests.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/django/core/serializers/python.py b/django/core/serializers/python.py index c129c068df..0eeb485797 100644 --- a/django/core/serializers/python.py +++ b/django/core/serializers/python.py @@ -84,7 +84,7 @@ def Deserializer(object_list, **options): # Handle FK fields elif field.rel and isinstance(field.rel, models.ManyToOneRel): - if field_value: + if field_value is not None: data[field.attname] = field.rel.to._meta.get_field(field.rel.field_name).to_python(field_value) else: data[field.attname] = None diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py index e49ab9de5c..6430c5b38d 100644 --- a/tests/regressiontests/serializers_regress/tests.py +++ b/tests/regressiontests/serializers_regress/tests.py @@ -261,6 +261,10 @@ The end."""), (fk_obj, 460, FKDataToO2O, 300), + # Regression test for #8651 -- FK = 0 + (data_obj, 0, Anchor, "Anchor 0"), + (fk_obj, 465, FKData, 0), + (im2m_obj, 470, M2MIntermediateData, None), #testing post- and prereferences and extra fields