Fixes circular list references
The depth deduciton for _fields was over zealous now max_depth is honoured/ Fixes #373
This commit is contained in:
parent
c775c0a80c
commit
a8d91a56bf
1
AUTHORS
1
AUTHORS
@ -75,4 +75,5 @@ that much better:
|
|||||||
* Karim Allah
|
* Karim Allah
|
||||||
* Adam Parrish
|
* Adam Parrish
|
||||||
* jpfarias
|
* jpfarias
|
||||||
|
* Alice Zoë Bevan-McGregor
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ Changelog
|
|||||||
Changes in dev
|
Changes in dev
|
||||||
==============
|
==============
|
||||||
|
|
||||||
|
- Fixed dereferencing - multi directional list dereferencing
|
||||||
- Fixed issue creating indexes with recursive embedded documents
|
- Fixed issue creating indexes with recursive embedded documents
|
||||||
- Fixed recursive lookup in _unique_with_indexes
|
- Fixed recursive lookup in _unique_with_indexes
|
||||||
- Fixed passing ComplexField defaults to constructor for ReferenceFields
|
- Fixed passing ComplexField defaults to constructor for ReferenceFields
|
||||||
|
@ -168,9 +168,9 @@ class DeReference(object):
|
|||||||
elif isinstance(v, (dict, pymongo.son.SON)) and '_ref' in v:
|
elif isinstance(v, (dict, pymongo.son.SON)) and '_ref' in v:
|
||||||
data[k]._data[field_name] = self.object_map.get(v['_ref'].id, v)
|
data[k]._data[field_name] = self.object_map.get(v['_ref'].id, v)
|
||||||
elif isinstance(v, dict) and depth <= self.max_depth:
|
elif isinstance(v, dict) and depth <= self.max_depth:
|
||||||
data[k]._data[field_name] = self._attach_objects(v, depth - 1, instance=instance, name=name)
|
data[k]._data[field_name] = self._attach_objects(v, depth, instance=instance, name=name)
|
||||||
elif isinstance(v, (list, tuple)) and depth <= self.max_depth:
|
elif isinstance(v, (list, tuple)) and depth <= self.max_depth:
|
||||||
data[k]._data[field_name] = self._attach_objects(v, depth - 1, instance=instance, name=name)
|
data[k]._data[field_name] = self._attach_objects(v, depth, instance=instance, name=name)
|
||||||
elif isinstance(v, (dict, list, tuple)) and depth <= self.max_depth:
|
elif isinstance(v, (dict, list, tuple)) and depth <= self.max_depth:
|
||||||
data[k] = self._attach_objects(v, depth - 1, instance=instance, name=name)
|
data[k] = self._attach_objects(v, depth - 1, instance=instance, name=name)
|
||||||
elif hasattr(v, 'id'):
|
elif hasattr(v, 'id'):
|
||||||
|
@ -760,3 +760,26 @@ class FieldTest(unittest.TestCase):
|
|||||||
UserB.drop_collection()
|
UserB.drop_collection()
|
||||||
UserC.drop_collection()
|
UserC.drop_collection()
|
||||||
Group.drop_collection()
|
Group.drop_collection()
|
||||||
|
|
||||||
|
def test_multidirectional_lists(self):
|
||||||
|
|
||||||
|
class Asset(Document):
|
||||||
|
name = StringField(max_length=250, required=True)
|
||||||
|
parent = GenericReferenceField(default=None)
|
||||||
|
parents = ListField(GenericReferenceField())
|
||||||
|
children = ListField(GenericReferenceField())
|
||||||
|
|
||||||
|
Asset.drop_collection()
|
||||||
|
|
||||||
|
root = Asset(name='', path="/", title="Site Root")
|
||||||
|
root.save()
|
||||||
|
|
||||||
|
company = Asset(name='company', title='Company', parent=root, parents=[root])
|
||||||
|
company.save()
|
||||||
|
|
||||||
|
root.children = [company]
|
||||||
|
root.save()
|
||||||
|
|
||||||
|
root = root.reload()
|
||||||
|
self.assertEquals(root.children, [company])
|
||||||
|
self.assertEquals(company.parents, [root])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user