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

Make the Redmine class picklable #64

Closed
rconradharris opened this issue Nov 3, 2014 · 0 comments · Fixed by #65
Closed

Make the Redmine class picklable #64

rconradharris opened this issue Nov 3, 2014 · 0 comments · Fixed by #65
Assignees
Labels

Comments

@rconradharris
Copy link
Contributor

The current getattr code attempts to create a Resource for any attribute accessed.

If an object that has a reference to Redmine is pickled, it will attempt to access `getstate`` which, in turn, will cause an exception like

  File "/Users/rick/.virtualenvs/openstack/lib/python2.7/site-packages/redmine/__init__.py", line 40, in __getattr__
    return ResourceManager(self, resource)
  File "/Users/rick/.virtualenvs/openstack/lib/python2.7/site-packages/redmine/managers.py", line 27, in __init__
    resource_name = ''.join(word[0].upper() + word[1:] for word in resource_name.split('_'))
  File "/Users/rick/.virtualenvs/openstack/lib/python2.7/site-packages/redmine/managers.py", line 27, in <genexpr>
    resource_name = ''.join(word[0].upper() + word[1:] for word in resource_name.split('_'))
IndexError: string index out of range

The proposed fix is to make Redmine's getattr raise an AttributeError the under-under methods. This will mean that __getstate__ is skipped.

Tested this approach and it worked.

rconradharris added a commit to rconradharris/python-redmine that referenced this issue Nov 3, 2014
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 and returns their value as-is.

Fixes maxtepkeev#64
rconradharris added a commit to rconradharris/python-redmine that referenced this issue Nov 3, 2014
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 and returns their value as-is.

Fixes maxtepkeev#64
@maxtepkeev maxtepkeev added the bug label Nov 4, 2014
@maxtepkeev maxtepkeev self-assigned this Nov 4, 2014
rconradharris added a commit to rconradharris/python-redmine that referenced this issue Nov 4, 2014
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 maxtepkeev#64
rconradharris added a commit to rconradharris/python-redmine that referenced this issue Nov 4, 2014
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 maxtepkeev#64
maxtepkeev added a commit that referenced this issue Nov 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants