diff options
| author | Tom Christie | 2013-02-22 22:59:55 +0000 |
|---|---|---|
| committer | Tom Christie | 2013-02-22 23:00:07 +0000 |
| commit | e1f0001f92b812c7406b009edff786dfbccc32cb (patch) | |
| tree | 2dfff2dd29982ebeed3d3ca6fe2c2b0c9ef6c557 /rest_framework/serializers.py | |
| parent | d62e4a7aa518b4f0658f8e88fad3f37c95e17082 (diff) | |
| download | django-rest-framework-e1f0001f92b812c7406b009edff786dfbccc32cb.tar.bz2 | |
Fix and test for #645
Yuck, pickle is weird. Closes #645.
Diffstat (limited to 'rest_framework/serializers.py')
| -rw-r--r-- | rest_framework/serializers.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 764313f7..266a2402 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -28,20 +28,23 @@ class DictWithMetadata(dict): def __getstate__(self): """ Used by pickle (e.g., caching). - Overriden to remove metadata from the dict, since it shouldn't be pickled - and may in some instances be unpickleable. + Overriden to remove the metadata from the dict, since it shouldn't be + pickled and may in some instances be unpickleable. """ - # return an instance of the first dict in MRO that isn't a DictWithMetadata - for base in self.__class__.__mro__: - if not issubclass(base, DictWithMetadata) and issubclass(base, dict): - return base(self) + return dict(self) -class SortedDictWithMetadata(SortedDict, DictWithMetadata): +class SortedDictWithMetadata(SortedDict): """ A sorted dict-like object, that can have additional properties attached. """ - pass + def __getstate__(self): + """ + Used by pickle (e.g., caching). + Overriden to remove the metadata from the dict, since it shouldn't be + pickle and may in some instances be unpickleable. + """ + return SortedDict(self).__dict__ def _is_protected_type(obj): |
