              field_name = obj.field.related_query_name()
              if field_name in attrs:
                  self.m2m_data[field_name] = attrs.pop(field_name)
  
          # Forward relations
          for field in self.opts.model._meta.many_to_many:
              if field.name in attrs:
                  self.m2m_data[field.name] = attrs.pop(field.name)
  
          instance = self.opts.model(**attrs)
          try:
              instance.full_clean(exclude=self.get_validation_exclusions())
          except ValidationError, err:
 
</s> remove         instance = self.opts.model(**attrs)
 </s> add  </s> remove         # Reverse relations
        for (obj, model) in self.opts.model._meta.get_all_related_m2m_objects_with_model():
            field_name = obj.field.related_query_name()
            if field_name in attrs:
                self.m2m_data[field_name] = attrs.pop(field_name)
 </s> add         else:
            # Reverse relations
            for (obj, model) in self.opts.model._meta.get_all_related_m2m_objects_with_model():
                field_name = obj.field.related_query_name()
                if field_name in attrs:
                    self.m2m_data[field_name] = attrs.pop(field_name)

            # Forward relations
            for field in self.opts.model._meta.many_to_many:
                if field.name in attrs:
                    self.m2m_data[field.name] = attrs.pop(field.name) </s> remove             return instance
 </s> add  </s> remove         response = self.view(request, pk=1).render()
 </s> add         response = self.view(request, pk='1').render()
            instance = self.opts.model(**attrs)
              field_name = obj.field.related_query_name()
              if field_name in attrs:
                  self.m2m_data[field_name] = attrs.pop(field_name)
  
            instance = self.opts.model(**attrs)
            instance = self.opts.model(**attrs)
            instance = self.opts.model(**attrs)
            instance = self.opts.model(**attrs)
  
          instance = self.opts.model(**attrs)
          try:
              instance.full_clean(exclude=self.get_validation_exclusions())
          except ValidationError, err:
keep keep keep keep replace replace replace replace keep keep keep keep keep
 Fix for pks returning as strings when set in pre_save.  Fixes #482. Thanks to @n8agrin for the bug report. 
rest_framework/serializers.py