Skip to content

Make the Redmine class picklable #64

@rconradharris

Description

@rconradharris

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.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions