ralphbean / taskw

python taskwarrior api
http://threebean.org
GNU General Public License v3.0
175 stars 47 forks source link

taskw in marshaling mode doesn't work with pickle #123

Open bergercookie opened 5 years ago

bergercookie commented 5 years ago

I'm trying the following sample:

import pickle
from taskw import TaskWarrior

tw = TaskWarrior(marshal=True)
t = tw.get_task(id=...)[-1]
pickle.dump(t, open('f', 'wb'))
pickle.load(open('f', 'rb')

And I'm getting the following error:

In [33]: pickle.load(open('f', 'rb'))
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-33-99235821b593> in <module>
----> 1 pickle.load(open('f', 'rb'))
~/.local/lib/python3.6/site-packages/taskw/task.py in __setitem__(self, key, value, force)
    216                     key,
    217                     self.get(key),
--> 218                     value,
    219                 )
    220
~/.local/lib/python3.6/site-packages/taskw/task.py in _record_change(self, key, from_, to)
    123
    124     def _record_change(self, key, from_, to):
--> 125         self._changes.append((key, from_, to))
    126
    127     def get_changes(self, serialized=False, keep=False):
AttributeError: 'Task' object has no attribute '_changes

If I explicitly set the protocol for pickle.dump to 0 or not use the marshal mode, it works fine.