diff --git a/tastypie/resources.py b/tastypie/resources.py index 4e8431c53..7c1fcdda6 100644 --- a/tastypie/resources.py +++ b/tastypie/resources.py @@ -616,7 +616,7 @@ def full_hydrate(self, bundle): if field_object.attribute: value = field_object.hydrate(bundle) - if value is not None: + if value is not None or field_object.null: # We need to avoid populating M2M data here as that will # cause things to blow up. if not getattr(field_object, 'is_related', False): diff --git a/tests/core/tests/resources.py b/tests/core/tests/resources.py index ee2953d76..6e6f1672d 100644 --- a/tests/core/tests/resources.py +++ b/tests/core/tests/resources.py @@ -265,34 +265,26 @@ def test_full_hydrate(self): self.assertEqual(hydrated.obj.view_count, 6) self.assertEqual(hydrated.obj.date_joined, datetime.datetime(2010, 2, 15, 12, 0, 0)) self.assertEqual(hydrated.obj.bar, 'O HAI BAR!') - - - # Test that a nullable value with a previous non-null value - # can be set to None + # Test that a nullable value with a previous non-null value + # can be set to None. nullable = NullableNameResource() - obj = nullable._meta.object_class() obj.name = "Daniel" - null_bundle = Bundle(obj=obj, data={'name': None}) hydrated = nullable.full_hydrate(null_bundle) - + self.assertTrue(hydrated.obj.name is None) - - + # Test that a nullable value with a previous non-null value # is not overridden if no value was given - obj = nullable._meta.object_class() obj.name = "Daniel" - empty_null_bundle = Bundle(obj=obj, data={}) hydrated = nullable.full_hydrate(empty_null_bundle) - + self.assertEquals(hydrated.obj.name, "Daniel") - def test_obj_get_list(self): basic = BasicResource() self.assertRaises(NotImplementedError, basic.obj_get_list)