Better fix for .save() _delta issue with DbRefs
refs: hmarr/mongoengine#518
This commit is contained in:
parent
9fecf2b303
commit
1a97dfd479
@ -1043,18 +1043,12 @@ 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
|
||||||
if '_id' in set_data:
|
if '_id' in set_data:
|
||||||
|
@ -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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user