From ea004b5e7a51ccf176545642692462dc2086056d Mon Sep 17 00:00:00 2001 From: Fernando Rocha Date: Mon, 11 Feb 2013 19:18:22 -0300 Subject: [PATCH] Make use o issubclass instead of isinstance (fix issue #645) Because __mro__ is a list of classes and not instances. DictWithMetadata.__getstate__ was never called Signed-off-by: Fernando Rocha --- rest_framework/serializers.py | 2 +- rest_framework/tests/serializer.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 4fb802a7c..df1e9fae9 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -31,7 +31,7 @@ class DictWithMetadata(dict): """ # return an instance of the first dict in MRO that isn't a DictWithMetadata for base in self.__class__.__mro__: - if not isinstance(base, DictWithMetadata) and isinstance(base, dict): + if not issubclass(base, DictWithMetadata) and issubclass(base, dict): return base(self) diff --git a/rest_framework/tests/serializer.py b/rest_framework/tests/serializer.py index 48b4f1ab9..4f4508f5b 100644 --- a/rest_framework/tests/serializer.py +++ b/rest_framework/tests/serializer.py @@ -870,6 +870,13 @@ class SerializerPickleTests(TestCase): fields = ('name', 'age') pickle.dumps(InnerPersonSerializer(Person(name="Noah", age=950)).data) + def test_getstate_method_should_not_return_none(self): + '''Regression test for + https://github.com/tomchristie/django-rest-framework/issues/645 + ''' + d = serializers.DictWithMetadata({1:1}) + self.assertEqual(d.__getstate__(), serializers.SortedDict({1:1})) + class DepthTest(TestCase): def test_implicit_nesting(self):