Skip to content

Commit

Permalink
Make Redmine class picklable
Browse files Browse the repository at this point in the history
The `Redmine` class couldn't be pickled because the `gettatr` would attempt to
turn any attribute access into a `Resource`, even `__getstate__`.

The proposed fix treats attributes that begin with an underscore (and
double-underscore) as non-`Resource` attributes.

Fixes #64
  • Loading branch information
rconradharris committed Nov 4, 2014
1 parent a827812 commit 34b081a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Changelog
a list)
- Fixed: `Issue #59 <https://github.com/maxtepkeev/python-redmine/issues/59>`__ (Raise ForbiddenError
when a 403 is encountered) (thanks to `Rick Harris <https://github.com/rconradharris>`__)
- Fixed: `Issue #64 <https://github.com/maxtepkeev/python-redmine/issues/64>`__ (Make the Redmine class picklable) (thanks to `Rick Harris <https://github.com/rconradharris>`__)

1.0.1 (2014-09-23)
++++++++++++++++++
Expand Down
3 changes: 3 additions & 0 deletions redmine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def __init__(self, url, **kwargs):

def __getattr__(self, resource):
"""Returns either ResourceSet or Resource object depending on the method used on the ResourceManager"""
if resource.startswith('_'):
raise AttributeError

return ResourceManager(self, resource)

def upload(self, filepath):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_redmine.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,12 @@ def test_auth(self):
self.response.status_code = 200
self.response.json = json_response({'user': {'firstname': 'John', 'lastname': 'Smith', 'id': 1}})
self.assertEqual(self.redmine.auth().firstname, 'John')

def test_getattr_on_under_attribute(self):
"""
Attributes that begin with an underscore should not be treated as a
`Resource`. The impetus of this was to make `Redmine` picklable by
preventing the `__getstate__` access from being treated a `Resource`.
"""
with self.assertRaises(AttributeError):
self.redmine.__getstate__

0 comments on commit 34b081a

Please sign in to comment.