|
|
@ -909,7 +909,9 @@ class BaseSchema(ma.SQLAlchemyAutoSchema, Storage):
|
|
|
|
# stabilize import of auto-increment primary keys (not required),
|
|
|
|
# stabilize import of auto-increment primary keys (not required),
|
|
|
|
# by matching import data to existing items and setting primary key
|
|
|
|
# by matching import data to existing items and setting primary key
|
|
|
|
if not self._primary in data:
|
|
|
|
if not self._primary in data:
|
|
|
|
for item in getattr(self.recall('parent'), self.recall('field', 'parent')):
|
|
|
|
parent = self.recall('parent')
|
|
|
|
|
|
|
|
if parent is not None:
|
|
|
|
|
|
|
|
for item in getattr(parent, self.recall('field', 'parent')):
|
|
|
|
existing = self.dump(item, many=False)
|
|
|
|
existing = self.dump(item, many=False)
|
|
|
|
this = existing.pop(self._primary)
|
|
|
|
this = existing.pop(self._primary)
|
|
|
|
if data == existing:
|
|
|
|
if data == existing:
|
|
|
@ -919,6 +921,11 @@ class BaseSchema(ma.SQLAlchemyAutoSchema, Storage):
|
|
|
|
|
|
|
|
|
|
|
|
# try to load instance
|
|
|
|
# try to load instance
|
|
|
|
instance = self.instance or self.get_instance(data)
|
|
|
|
instance = self.instance or self.get_instance(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# remember instance as parent for pruning siblings
|
|
|
|
|
|
|
|
if not self.Meta.sibling and self.context.get('update'):
|
|
|
|
|
|
|
|
self.store('parent', instance)
|
|
|
|
|
|
|
|
|
|
|
|
if instance is None:
|
|
|
|
if instance is None:
|
|
|
|
|
|
|
|
|
|
|
|
if '__delete__' in data:
|
|
|
|
if '__delete__' in data:
|
|
|
@ -931,9 +938,6 @@ class BaseSchema(ma.SQLAlchemyAutoSchema, Storage):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
|
|
|
if self.context.get('update'):
|
|
|
|
if self.context.get('update'):
|
|
|
|
# remember instance as parent for pruning siblings
|
|
|
|
|
|
|
|
if not self.Meta.sibling:
|
|
|
|
|
|
|
|
self.store('parent', instance)
|
|
|
|
|
|
|
|
# delete instance from session when marked
|
|
|
|
# delete instance from session when marked
|
|
|
|
if '__delete__' in data:
|
|
|
|
if '__delete__' in data:
|
|
|
|
self.opts.sqla_session.delete(instance)
|
|
|
|
self.opts.sqla_session.delete(instance)
|
|
|
@ -1014,8 +1018,10 @@ class BaseSchema(ma.SQLAlchemyAutoSchema, Storage):
|
|
|
|
del_items = True
|
|
|
|
del_items = True
|
|
|
|
|
|
|
|
|
|
|
|
if add_items or del_items:
|
|
|
|
if add_items or del_items:
|
|
|
|
|
|
|
|
parent = self.recall('parent')
|
|
|
|
|
|
|
|
if parent is not None:
|
|
|
|
existing = {item[self._primary] for item in items if self._primary in item}
|
|
|
|
existing = {item[self._primary] for item in items if self._primary in item}
|
|
|
|
for item in getattr(self.recall('parent'), self.recall('field', 'parent')):
|
|
|
|
for item in getattr(parent, self.recall('field', 'parent')):
|
|
|
|
key = getattr(item, self._primary)
|
|
|
|
key = getattr(item, self._primary)
|
|
|
|
if key not in existing:
|
|
|
|
if key not in existing:
|
|
|
|
if add_items:
|
|
|
|
if add_items:
|
|
|
|