Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3628 by implementing __getnewargs__() #3701

Merged
merged 6 commits into from
Dec 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rest_framework/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def __new__(self, url, name):
ret.name = name
return ret

def __getnewargs__(self):
return(str(self), self.name,)

is_hyperlink = True


Expand Down
11 changes: 11 additions & 0 deletions tests/test_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,14 @@ def test_get_value_multi_dictionary_partial(self):

mvd = MultiValueDict({'baz': ['bar1', 'bar2']})
assert empty == self.field.get_value(mvd)


class TestHyperlink:
def setup(self):
self.default_hyperlink = serializers.Hyperlink('http://example.com', 'test')

def test_can_be_pickled(self):
import pickle
upkled = pickle.loads(pickle.dumps(self.default_hyperlink))
assert upkled == self.default_hyperlink
assert upkled.name == self.default_hyperlink.name