jsonpickle/jsonpickle — Issue #23: unpickable raises RuntimeError: maximum recursion depth exceeded
Author: toddself
Created: 2012-01-03 20:30:54+00:00
State: open

Using this class:
```python
class Hop(SQLObject):
BITTERING = 0
AROMA = 1
BOTH = 2
LEAF = 0
PELLET = 1
PLUG = 2
hop_types = ['Bittering', 'Aroma', 'Both',]
hop_forms = ['Leaf', 'Pellet', 'Plug',]

hop_type = IntCol(default=BITTERING)
hop_form = IntCol(default=LEAF)
alpha = PercentCol(default=0.0)
beta = PercentCol(default=0.0)
stability = PercentCol(default=0.0)
origin = UnicodeCol(default=None)
name = UnicodeCol(length=64, default=None)
description = UnicodeCol(default=None)
substitutes = RelatedJoin('Hop',
joinColumn='master_hop',
otherColumn='substitute_hop',
addRemoveName="Substitute",
intermediateTable="substitute_hops",
createRelatedTable=True)
versions = Versioning()

def _get_hop_type(self):
return Hop.hop_types[self._SO_get_hop_type()]

def _get_hop_form(self):
return Hop.hop_forms[self._SO_get_hop_form()]

def _get_short_description(self):
if self.description and len(self.description) > 64:
return self.description[:64]+"..."
else:
return self.description

def _get_inventory(self):
try:
inv = list(Inventory.select(Inventory.q.hop == self.id))[0]
except:
return 0

return "%s %s" % (inv.amount, Measure.Measure[inv.amount_units])
```

```python
>>> import jsonpickle
>>> import beerlog
>>> hop = beerlog.Hop.get(1)
>>> hop

>>> jsonpickle.encode(hop)
'{"py/object": "beerlog.brewery.models.Hop", "py/state": {"_SO_val_origin": null, "_SO_validatorState": {"py/object": "sqlobject.sqlbuilder.SQLObjectState", "connection": null, "soObject": {"py/object": "beerlog.brewery.models.Hop", "py/state": {"_SO_val_origin": null, "_SO_validatorState": {"py/id": 1}, "_SO_val_hop_type": 0, "_SO_val_stability": 0, "_SO_val_name": "Amarillo", "id": 1, "_SO_val_alpha": 0, "_SO_val_hop_form": 0, "_SO_val_beta": 0, "_SO_val_description": null, "_SO_createValues": {}}}}, "_SO_val_hop_type": 0, "_SO_val_stability": 0, "_SO_val_name": "Amarillo", "id": 1, "_SO_val_alpha": 0, "_SO_val_hop_form": 0, "_SO_val_beta": 0, "_SO_val_description": null, "_SO_createValues": {}}}'
>>> jsonpickle.decode(jsonpickle.encode(hop))

>>> jsonpickle.encode(hop, unpicklable=False)
Traceback (most recent call last):
File "", line 1, in
File "/Users/tkennedy/src/beerlog/env/lib/python2.7/site-packages/jsonpickle/__init__.py", line 313, in encode
return json.encode(j.flatten(value))
File "/Users/tkennedy/src/beerlog/env/lib/python2.7/site-packages/jsonpickle/pickler.py", line 136, in flatten
return self._pop(self._flatten_obj_instance(obj))
File "/Users/tkennedy/src/beerlog/env/lib/python2.7/site-packages/jsonpickle/pickler.py", line 197, in _flatten_obj_instance
state = self.flatten(obj.__getstate__())
File "/Users/tkennedy/src/beerlog/env/lib/python2.7/site-packages/jsonpickle/pickler.py", line 127, in flatten
return self._pop(self._flatten_dict_obj(obj, obj.__class__()))
File "/Users/tkennedy/src/beerlog/env/lib/python2.7/site-packages/jsonpickle/pickler.py", line 215, in _flatten_dict_obj
self._flatten_key_value_pair(k, v, data)
File "/Users/tkennedy/src/beerlog/env/lib/python2.7/site-packages/jsonpickle/pickler.py", line 234, in _flatten_key_value_pair
data[k] = self.flatten(v)
File "/Users/tkennedy/src/beerlog/env/lib/python2.7/site-packages/jsonpickle/pickler.py", line 136, in flatten
return self._pop(self._flatten_obj_instance(obj))
File "/Users/tkennedy/src/beerlog/env/lib/python2.7/site-packages/jsonpickle/pickler.py", line 206, in _flatten_obj_instance
return self._flatten_dict_obj(obj.__dict__, data)
File "/Users/tkennedy/src/beerlog/env/lib/python2.7/site-packages/jsonpickle/pickler.py", line 215, in _flatten_dict_obj
self._flatten_key_value_pair(k, v, data)
File "/Users/tkennedy/src/beerlog/env/lib/python2.7/site-packages/jsonpickle/pickler.py", line 234, in _flatten_key_value_pair
data[k] = self.flatten(v)

# keeps going quite a while!!!

File "/Users/tkennedy/src/beerlog/env/lib/python2.7/site-packages/jsonpickle/pickler.py", line 129, in flatten
if util.is_type(obj):
File "/Users/tkennedy/src/beerlog/env/lib/python2.7/site-packages/jsonpickle/util.py", line 40, in is_type
return type(obj) is types.TypeType or repr(obj).startswith('>>