summaryrefslogtreecommitdiffstats
path: root/openstack
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2012-07-18 16:15:52 -0400
committerRussell Bryant <rbryant@redhat.com>2012-07-18 16:15:52 -0400
commit2d6f84742a3e8ea51ebbfb82cbeacefe97e199d5 (patch)
treef35bda4f63f632f622d1c620d9ab6246aa22eeaa /openstack
parent1c1b36985be5a4c49b9cfc808edcdfd288c6d0cc (diff)
downloadoslo-2d6f84742a3e8ea51ebbfb82cbeacefe97e199d5.tar.gz
oslo-2d6f84742a3e8ea51ebbfb82cbeacefe97e199d5.tar.xz
oslo-2d6f84742a3e8ea51ebbfb82cbeacefe97e199d5.zip
Track to_primitive() depth after iteritems().
Change jsonutils.to_primitive() to increase the recursion depth counter when calling to_primitive() on the result of iteritems() from the current element. Previously, the only time the counter was increased was when converting the __dict__ from an object. The iteritems() case risks cycles, as well. I hit a problem with this when trying to call to_primitive on an instance of nova.db.sqlalchemy.models.Instance. An Instance includes a reference to InstanceInfoCache, which has a reference back to the Instance. Without this change, to_primitive() would raise an exception for an Instance due to excessive recursion. Related to nova blueprint no-db-messaging. Change-Id: Ifb878368d97e92ab6c361a4dd5f5ab2e68fc16e2
Diffstat (limited to 'openstack')
-rw-r--r--openstack/common/jsonutils.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/openstack/common/jsonutils.py b/openstack/common/jsonutils.py
index 6130a7f..e8e14c4 100644
--- a/openstack/common/jsonutils.py
+++ b/openstack/common/jsonutils.py
@@ -107,7 +107,7 @@ def to_primitive(value, convert_instances=False, level=0):
elif hasattr(value, 'iteritems'):
return to_primitive(dict(value.iteritems()),
convert_instances=convert_instances,
- level=level)
+ level=level + 1)
elif hasattr(value, '__iter__'):
return to_primitive(list(value), level)
elif convert_instances and hasattr(value, '__dict__'):