From 211c19c579a8f285f666f405a0081b1080ec7622 Mon Sep 17 00:00:00 2001 From: mick Date: Fri, 5 Jun 2015 15:58:36 +0100 Subject: [PATCH] Fix for ticket 12685 --- django/core/serializers/base.py | 4 ++-- tests/serializers/tests.py | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/django/core/serializers/base.py b/django/core/serializers/base.py index e678e78463..23a0c7b72f 100644 --- a/django/core/serializers/base.py +++ b/django/core/serializers/base.py @@ -166,11 +166,11 @@ class DeserializedObject(object): return "" % ( self.object._meta.label, self.object.pk) - def save(self, save_m2m=True, using=None): + def save(self, save_m2m=True, using=None, **kwargs): # Call save on the Model baseclass directly. This bypasses any # model-defined save. The save is also forced to be raw. # raw=True is passed to any pre/post_save signals. - models.Model.save_base(self.object, using=using, raw=True) + models.Model.save_base(self.object, using=using, raw=True, **kwargs) if self.m2m_data and save_m2m: for accessor_name, object_list in self.m2m_data.items(): setattr(self.object, accessor_name, object_list) diff --git a/tests/serializers/tests.py b/tests/serializers/tests.py index c223fc4036..f9b65cba82 100644 --- a/tests/serializers/tests.py +++ b/tests/serializers/tests.py @@ -11,7 +11,7 @@ from xml.dom import minidom from django.core import management, serializers from django.db import connection, transaction from django.test import ( - SimpleTestCase, TestCase, TransactionTestCase, override_settings, + SimpleTestCase, TestCase, TransactionTestCase, mock, override_settings, skipUnlessDBFeature, ) from django.test.utils import Approximate @@ -278,6 +278,14 @@ class SerializersTestBase(object): 'second_category_pk': categories[1], }) + def test_deserialize_force_insert(self): + """Tests that deserialized content can be saved with force_insert as a parameter.""" + serial_str = serializers.serialize(self.serializer_name, [self.a1]) + deserial_obj = list(serializers.deserialize(self.serializer_name, serial_str))[0] + with mock.patch('django.db.models.Model') as mock_model: + deserial_obj.save(force_insert=False) + mock_model.save_base.assert_called_with(deserial_obj.object, raw=True, using=None, force_insert=False) + class SerializersTransactionTestBase(object):