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