Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions functions/api/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,41 @@ def update_instance(manifestation_id: str):
return jsonify({"message": "Manifestation updated successfully", "id": manifestation_id}), 200


@instances_bp.route("/<string:manifestation_id>", methods=["DELETE"], strict_slashes=False)
def delete_instance(manifestation_id: str):
"""Delete a manifestation and all its owned nodes (cascade)."""
logger.info("Deleting manifestation with ID: %s", manifestation_id)

db = Neo4JDatabase()
result = db.delete_manifestation(manifestation_id=manifestation_id)

expression_id = result["expression_id"]
if expression_id:
try:
Storage().delete_base_text(expression_id=expression_id, manifestation_id=manifestation_id)
except Exception as exc: # pylint: disable=broad-exception-caught
# Storage cleanup is best-effort: the request must not fail just because the blob
# is missing or storage is temporarily unreachable. Log full exception details so
# any non-NotFound errors (auth, network, programming bugs) remain visible.
logger.warning(
"Failed to delete base text for expression %s / manifestation %s: %s — skipping",
expression_id,
manifestation_id,
exc,
)

if result["segment_ids"]:
_trigger_delete_search_segments(result["segment_ids"])

return jsonify({
"message": "Instance deleted successfully",
"instance_id": manifestation_id,
"expression_id": expression_id,
"annotations": result["annotations"],
"deleted_counts": result["deleted_counts"],
}), 200


def _create_aligned_text(
request_model: AlignedTextRequestModel, text_type: TextType, target_manifestation_id: str
) -> tuple[Response, int]:
Expand Down
Loading