diff --git a/server/planning/assignments/assignments.py b/server/planning/assignments/assignments.py index 76790564a..f285f6f41 100644 --- a/server/planning/assignments/assignments.py +++ b/server/planning/assignments/assignments.py @@ -1195,7 +1195,7 @@ def on_delete(self, doc): """ Validate that we have a lock on the Assignment and it's associated Planning item """ - if doc.get("_to_delete") is True: + if doc.get("_to_delete") is True or not request: # Already marked for delete - no validation needed (could be the background job) return diff --git a/server/planning/planning/planning.py b/server/planning/planning/planning.py index 8712345f6..fac3e8ad2 100644 --- a/server/planning/planning/planning.py +++ b/server/planning/planning/planning.py @@ -15,7 +15,7 @@ import logging from datetime import datetime -from flask import json, current_app as app +from flask import json, current_app as app, request from eve.methods.common import resolve_document_etag import superdesk @@ -1274,23 +1274,24 @@ def delete_assignments_for_coverages(self, coverages, notify=True): if original_assigment: assignment_service.system_update(ObjectId(assign_id), {"_to_delete": True}, original_assigment) - session_id = get_auth().get("_id") - user_id = get_user().get(config.ID_FIELD) - if len(deleted_assignments) > 0: - push_notification( - "assignments:delete", - items=deleted_assignments, - session=session_id, - user=user_id, - ) + if request: + session_id = get_auth().get("_id") + user_id = get_user().get(config.ID_FIELD) + if len(deleted_assignments) > 0: + push_notification( + "assignments:delete", + items=deleted_assignments, + session=session_id, + user=user_id, + ) - if len(failed_assignments) > 0 and notify: - push_notification( - "assignments:delete:fail", - items=failed_assignments, - session=session_id, - user=user_id, - ) + if len(failed_assignments) > 0 and notify: + push_notification( + "assignments:delete:fail", + items=failed_assignments, + session=session_id, + user=user_id, + ) def get_expired_items(self, expiry_datetime, spiked_planning_only=False): """Get the expired items