          try:
              value = getattr(obj, self.source or field_name)
          except ObjectDoesNotExist:
              return None
          return self.to_native(value)
  
      def field_from_native(self, data, files, field_name, into):
          if self.read_only:
              return
  
 
</s> remove class SluggedNullableForeignKeyTests(TestCase):

 </s> add class SlugNullableForeignKeyTests(TestCase): </s> remove     def test_slug_foreign_key_retrieve_with_null(self):
 </s> add     def test_foreign_key_retrieve_with_null(self): </s> remove         #BUG: Throws AttributeError - NoneType object has no attribute 'name'
        self.assertEquals(serializer.data, data)
        self.assertEqual(obj.name, u'source-4')

        #If null = True then target should be None
        serializer = NotRequiredSluggedNullableForeignKeySourceSerializer(data=data)
        #BUG: test case fails
        self.assertTrue(serializer.is_valid())
        #BUG: serializer.errors = {'target': [u'Value may not be null']}
        #BUG: serializer does not save object (But it can because its not required)
        obj = serializer.save()
        #BUG: Throws AttributeError - NoneType object has no attribute 'name'
 </s> add  </s> remove         #BUG: serializer.errors = {'target': [u'Value may not be null']}
        #BUG: Serializer does not use default value to save object
 </s> add  </s> remove         serializer = SluggedNullableForeignKeySourceSerializer(queryset)
        #Throws 
        self.assertEquals(serializer.data, expected)

    def test_slug_foreign_key_create_with_valid_null(self):
        data = {'name': u'source-4', 'target': None}
        default_data = {'name': u'source-4', 'target': 'N/A'}

        serializer = SluggedNullableForeignKeySourceSerializer(data=data)
        self.assertFalse(serializer.is_valid())
        self.assertEquals(serializer.errors, {'target': [u'Value may not be null']})


        #If attribute not required, data should match
        serializer = NullOKSluggedNullableForeignKeySourceSerializer(data=data)
        self.assertTrue(serializer.is_valid())
        obj = serializer.save()
        #BUG: Throws AttributeError: "NoneType object has no attribute 'name'"
        self.assertEquals(serializer.data, data)
        self.assertEqual(obj.name, u'source-4')

        #If default = 'N/A' then target should pass validation, and be the default ('N/A')
        serializer = DefaultSluggedNullableForeignKeySourceSerializer(data=data)
        #BUG: test case fails
 </s> add     def test_foreign_key_create_with_valid_null(self):
        data = {'id': 4, 'name': u'source-4', 'target': None}
        serializer = NullableSlugSourceSerializer(data=data)
        if value is None:
            return None
          try:
              value = getattr(obj, self.source or field_name)
          except ObjectDoesNotExist:
              return None
        if value is None:
            return None
          return self.to_native(value)
  
      def field_from_native(self, data, files, field_name, into):
          if self.read_only:
              return
  
keep keep keep add keep keep keep keep keep keep
 Drop bits of relations_slug tests which don't mirror existing tests. 
rest_framework/relations.py