Serializable ununpickleable

Bug #1192845 reported by Stuart Bishop
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Charm Helpers
Fix Released
Undecided
Stuart Bishop

Bug Description

Serializable instances can be pickled, but cannot be unpickled.

>>> from charmhelpers.core.hookenv import Serializable
>>> import pickle
>>> s = Serializable({})
>>> pickle.dumps(s)
"(icharmhelpers.core.hookenv\nSerializable\np0\n(dp1\nS'data'\np2\n(dp3\nsb."
>>> pickle.loads(pickle.dumps(s))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/pickle.py", line 1382, in loads
    return Unpickler(file).load()
  File "/usr/lib/python2.7/pickle.py", line 858, in load
    dispatch[key](self)
  File "/usr/lib/python2.7/pickle.py", line 1215, in load_build
    setstate = getattr(inst, "__setstate__", None)
  File "charmhelpers/core/hookenv.py", line 81, in __getattr__
    got = getattr(self.data, attr, MARKER)
  File "charmhelpers/core/hookenv.py", line 79, in __getattr__
    return self.__dict__[attr]
KeyError: 'data'
>>>

Related branches

Revision history for this message
Stuart Bishop (stub) wrote :

Workaround is to manually unwrap objects return from hookenv tools, as it implicitly wraps stuff with the magic helper.

Revision history for this message
Stuart Bishop (stub) wrote :

See also Bug #1182959. Is it that bad to explicitly spell things Serializable(my_dict).json() rather than my_pseudo_dict.json() ?

Stuart Bishop (stub)
Changed in charm-helpers:
assignee: nobody → Stuart Bishop (stub)
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.