CORD-1349 allow coreapi to GET and UPDATE deleted objects; fix sync step
Change-Id: I9cad0f1d578b31cb71cfc066590663957f5c9762
diff --git a/xos/coreapi/apihelper.py b/xos/coreapi/apihelper.py
index 875c89f..e64a8a2 100644
--- a/xos/coreapi/apihelper.py
+++ b/xos/coreapi/apihelper.py
@@ -244,8 +244,22 @@
return p_objs
+ def get_live_or_deleted_object(self, djangoClass, id):
+ """ Given an id, retrieve the object regardless of whether the object is live or deleted. """
+ obj = None
+ # First, check to see if the object has been deleted. Maybe the caller is
+ # trying to update the policed timestamp of a deleted object.
+ if hasattr(djangoClass, "deleted_objects"):
+ deleted_objects = djangoClass.deleted_objects.filter(id=id)
+ if deleted_objects:
+ obj = deleted_objects[0]
+ # No deleted object was found, so check for a live object.
+ if not obj:
+ obj = djangoClass.objects.get(id=id)
+ return obj
+
def get(self, djangoClass, id):
- obj = djangoClass.objects.get(id=id)
+ obj = self.get_live_or_deleted_object(djangoClass, id)
return self.objToProto(obj)
def create(self, djangoClass, user, request):
@@ -258,7 +272,7 @@
return self.objToProto(new_obj)
def update(self, djangoClass, user, id, message, context):
- obj = djangoClass.objects.get(id=id)
+ obj = self.get_live_or_deleted_object(djangoClass, id)
obj.caller = user
if (not user) or (not obj.can_update(user)):
raise XOSPermissionDenied()
diff --git a/xos/synchronizers/new_base/syncstep.py b/xos/synchronizers/new_base/syncstep.py
index 492351a..cb3de5f 100644
--- a/xos/synchronizers/new_base/syncstep.py
+++ b/xos/synchronizers/new_base/syncstep.py
@@ -170,7 +170,7 @@
path = ''.join(main_objs.__name__).lower()
tenant_fields['delete']=True
- res = run_template(self.playbook, tenant_fields, ath=path)
+ res = run_template(self.playbook, tenant_fields, path=path)
try:
self.map_delete_outputs(o,res)
except AttributeError: