diff options
| author | Ben Roberts | 2012-12-05 17:43:47 -0700 |
|---|---|---|
| committer | Ben Roberts | 2012-12-05 17:43:47 -0700 |
| commit | 705c7ad09db65c6ea6fb69bbd417cb7a45f6e3b9 (patch) | |
| tree | d4c804bb98828bef6984adcd7a07a58644a9021f /rest_framework/serializers.py | |
| parent | 3868241f6acda96fbd08cc81211b09ffbc2f38b3 (diff) | |
| download | django-rest-framework-705c7ad09db65c6ea6fb69bbd417cb7a45f6e3b9.tar.bz2 | |
added tests and fix for unpickleable metadata in SortedDictWithMetadata
Diffstat (limited to 'rest_framework/serializers.py')
| -rw-r--r-- | rest_framework/serializers.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 4519ab05..fcc0744a 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -22,7 +22,16 @@ class DictWithMetadata(dict): """ A dict-like object, that can have additional properties attached. """ - pass + + 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. + """ + # 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): + return base(self) class SortedDictWithMetadata(SortedDict, DictWithMetadata): @@ -32,6 +41,7 @@ class SortedDictWithMetadata(SortedDict, DictWithMetadata): pass + def _is_protected_type(obj): """ True if the object is a native datatype that does not need to |
