Better fix for .save() _delta issue with DbRefs

refs: hmarr/mongoengine#518
This commit is contained in:
Ross Lawley 2012-06-19 14:05:53 +01:00
parent 9fecf2b303
commit 1a97dfd479
2 changed files with 3 additions and 8 deletions

View File

@ -1043,17 +1043,11 @@ Invalid data to create a `%s` instance.\n%s""".strip() % (cls._class_name, error
for path in set_fields: for path in set_fields:
parts = path.split('.') parts = path.split('.')
d = doc d = doc
dbref = False
for p in parts: for p in parts:
if isinstance(d, DBRef): if p.isdigit():
dbref = True
elif hasattr(d, '__getattr__'):
d = getattr(p, d)
elif p.isdigit():
d = d[int(p)] d = d[int(p)]
else: else:
d = d.get(p) d = d.get(p)
if not dbref:
set_data[path] = d set_data[path] = d
else: else:
set_data = doc set_data = doc

View File

@ -226,6 +226,7 @@ class Document(BaseDocument):
if cascade_kwargs: # Allow granular control over cascades if cascade_kwargs: # Allow granular control over cascades
kwargs.update(cascade_kwargs) kwargs.update(cascade_kwargs)
kwargs['_refs'] = _refs kwargs['_refs'] = _refs
self._changed_fields = []
self.cascade_save(**kwargs) self.cascade_save(**kwargs)
except pymongo.errors.OperationFailure, err: except pymongo.errors.OperationFailure, err: