Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
6ffcd7ba
Commit
6ffcd7ba
authored
Dec 06, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #477 from roberts81/master
Fix for #460
parents
6a5f4f2a
cb7d9ea5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
2 deletions
+35
-2
rest_framework/serializers.py
+10
-1
rest_framework/tests/serializer.py
+25
-1
No files found.
rest_framework/serializers.py
View file @
6ffcd7ba
...
@@ -22,7 +22,16 @@ class DictWithMetadata(dict):
...
@@ -22,7 +22,16 @@ class DictWithMetadata(dict):
"""
"""
A dict-like object, that can have additional properties attached.
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
):
class
SortedDictWithMetadata
(
SortedDict
,
DictWithMetadata
):
...
...
rest_framework/tests/serializer.py
View file @
6ffcd7ba
import
datetime
import
datetime
,
pickle
from
django.test
import
TestCase
from
django.test
import
TestCase
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
rest_framework.tests.models
import
(
ActionItem
,
Anchor
,
BasicModel
,
from
rest_framework.tests.models
import
(
ActionItem
,
Anchor
,
BasicModel
,
...
@@ -682,3 +682,27 @@ class BlankFieldTests(TestCase):
...
@@ -682,3 +682,27 @@ class BlankFieldTests(TestCase):
"""
"""
serializer
=
self
.
not_blank_model_serializer_class
(
data
=
self
.
data
)
serializer
=
self
.
not_blank_model_serializer_class
(
data
=
self
.
data
)
self
.
assertEquals
(
serializer
.
is_valid
(),
False
)
self
.
assertEquals
(
serializer
.
is_valid
(),
False
)
#test for issue #460
class
SerializerPickleTests
(
TestCase
):
"""
Test pickleability of the output of Serializers
"""
def
test_pickle_simple_model_serializer_data
(
self
):
"""
Test simple serializer
"""
pickle
.
dumps
(
PersonSerializer
(
Person
(
name
=
"Methusela"
,
age
=
969
))
.
data
)
def
test_pickle_inner_serializer
(
self
):
"""
Test pickling a serializer whose resulting .data (a SortedDictWithMetadata) will
have unpickleable meta data--in order to make sure metadata doesn't get pulled into the pickle.
See DictWithMetadata.__getstate__
"""
class
InnerPersonSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Person
fields
=
(
'name'
,
'age'
)
pickle
.
dumps
(
InnerPersonSerializer
(
Person
(
name
=
"Noah"
,
age
=
950
))
.
data
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment