Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

refactor: extract _validate_document_ids() to deduplicate bulk delete validation (#3136)

LearningCircuit1f3b99bcee5e
diff --git a/src/local_deep_research/research_library/deletion/routes/delete_routes.py b/src/local_deep_research/research_library/deletion/routes/delete_routes.py
index d5692a333c..e88065296e 100644
--- a/src/local_deep_research/research_library/deletion/routes/delete_routes.py
+++ b/src/local_deep_research/research_library/deletion/routes/delete_routes.py
@@ -27,6 +27,40 @@ delete_bp = Blueprint("delete", __name__, url_prefix="/library/api")
# if the decorator is ever removed.
+def _validate_document_ids():
+ """Extract and validate document_ids from the JSON request body.
+
+ Returns:
+ tuple: (document_ids, error_response) where error_response is None
+ on success, or a (jsonify(...), status_code) tuple on failure.
+ """
+ data = request.get_json()
+ if not data or "document_ids" not in data:
+ return None, (
+ jsonify(
+ {
+ "success": False,
+ "error": "document_ids required in request body",
+ }
+ ),
+ 400,
+ )
+
+ document_ids = data["document_ids"]
+ if not isinstance(document_ids, list) or not document_ids:
+ return None, (
+ jsonify(
+ {
+ "success": False,
+ "error": "document_ids must be a non-empty list",
+ }
+ ),
+ 400,
+ )
+
+ return document_ids, None
+
+
# =============================================================================
# Document Delete Endpoints
# =============================================================================
@@ -251,23 +285,9 @@ def delete_documents_bulk():
JSON with bulk deletion results
"""
try:
- data = request.get_json()
- if not data or "document_ids" not in data:
- return jsonify(
- {
- "success": False,
- "error": "document_ids required in request body",
- }
- ), 400
-
- document_ids = data["document_ids"]
- if not isinstance(document_ids, list) or not document_ids:
- return jsonify(
- {
- "success": False,
- "error": "document_ids must be a non-empty list",
- }
- ), 400
+ document_ids, error = _validate_document_ids()
+ if error:
+ return error
username = session["username"]
service = BulkDeletionService(username)
@@ -295,23 +315,9 @@ def delete_documents_blobs_bulk():
JSON with bulk blob deletion results
"""
try:
- data = request.get_json()
- if not data or "document_ids" not in data:
- return jsonify(
- {
- "success": False,
- "error": "document_ids required in request body",
- }
- ), 400
-
- document_ids = data["document_ids"]
- if not isinstance(document_ids, list) or not document_ids:
- return jsonify(
- {
- "success": False,
- "error": "document_ids must be a non-empty list",
- }
- ), 400
+ document_ids, error = _validate_document_ids()
+ if error:
+ return error
username = session["username"]
service = BulkDeletionService(username)
@@ -340,23 +346,9 @@ def remove_documents_from_collection_bulk(collection_id):
JSON with bulk removal results
"""
try:
- data = request.get_json()
- if not data or "document_ids" not in data:
- return jsonify(
- {
- "success": False,
- "error": "document_ids required in request body",
- }
- ), 400
-
- document_ids = data["document_ids"]
- if not isinstance(document_ids, list) or not document_ids:
- return jsonify(
- {
- "success": False,
- "error": "document_ids must be a non-empty list",
- }
- ), 400
+ document_ids, error = _validate_document_ids()
+ if error:
+ return error
username = session["username"]
service = BulkDeletionService(username)
@@ -386,26 +378,13 @@ def get_bulk_deletion_preview():
JSON with preview information
"""
try:
- data = request.get_json()
- if not data or "document_ids" not in data:
- return jsonify(
- {
- "success": False,
- "error": "document_ids required in request body",
- }
- ), 400
+ document_ids, error = _validate_document_ids()
+ if error:
+ return error
- document_ids = data["document_ids"]
+ data = request.get_json()
operation = data.get("operation", "delete")
- if not isinstance(document_ids, list) or not document_ids:
- return jsonify(
- {
- "success": False,
- "error": "document_ids must be a non-empty list",
- }
- ), 400
-
username = session["username"]
service = BulkDeletionService(username)
result = service.get_bulk_preview(document_ids, operation)