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.

fix: remove duplicate delete_collection route that shadowed canonical endpoint (#3150)

LearningCircuit4dba7a721bc9
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 e88065296e..652e625493 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
@@ -192,23 +192,25 @@ def delete_collection(collection_id):
"""
Delete a collection and clean up all related data.
- Documents are preserved but unlinked. RAG index and chunks are deleted.
-
- Tooltip: "Delete this collection. Documents will remain in the library
- but will be unlinked from this collection."
+ Deletes the collection, its RAG index, chunks, and any orphaned
+ documents (documents not in any other collection).
Returns:
- JSON with deletion details
+ JSON with deletion details including orphaned documents deleted
"""
try:
username = session["username"]
service = CollectionDeletionService(username)
- result = service.delete_collection(collection_id)
+ result = service.delete_collection(
+ collection_id, delete_orphaned_documents=True
+ )
if result.get("deleted"):
return jsonify({"success": True, **result})
else:
- return jsonify({"success": False, **result}), 404
+ error = result.get("error", "Unknown error")
+ status_code = 404 if "not found" in error.lower() else 400
+ return jsonify({"success": False, **result}), status_code
except Exception as e:
return handle_api_error("deleting collection", e)
diff --git a/src/local_deep_research/research_library/routes/rag_routes.py b/src/local_deep_research/research_library/routes/rag_routes.py
index cc7beed567..f7e3b1dc6e 100644
--- a/src/local_deep_research/research_library/routes/rag_routes.py
+++ b/src/local_deep_research/research_library/routes/rag_routes.py
@@ -1312,41 +1312,6 @@ def update_collection(collection_id):
return handle_api_error("updating collection", e)
-@rag_bp.route("/api/collections/<string:collection_id>", methods=["DELETE"])
-@login_required
-def delete_collection(collection_id):
- """Delete a collection and its orphaned documents."""
- from ..deletion.services.collection_deletion import (
- CollectionDeletionService,
- )
-
- try:
- username = session["username"]
- service = CollectionDeletionService(username)
- result = service.delete_collection(
- collection_id, delete_orphaned_documents=True
- )
-
- if result.get("deleted"):
- return jsonify(
- {
- "success": True,
- "message": "Collection deleted successfully",
- "deleted_chunks": result.get("chunks_deleted", 0),
- "orphaned_documents_deleted": result.get(
- "orphaned_documents_deleted", 0
- ),
- }
- )
- else:
- error = result.get("error", "Unknown error")
- status_code = 404 if "not found" in error.lower() else 400
- return jsonify({"success": False, "error": error}), status_code
-
- except Exception as e:
- return handle_api_error("deleting collection", e)
-
-
@rag_bp.route(
"/api/collections/<string:collection_id>/upload", methods=["POST"]
)
diff --git a/tests/research_library/deletion/routes/test_delete_routes_http.py b/tests/research_library/deletion/routes/test_delete_routes_http.py
index e033b12343..b4c4d4858b 100644
--- a/tests/research_library/deletion/routes/test_delete_routes_http.py
+++ b/tests/research_library/deletion/routes/test_delete_routes_http.py
@@ -320,6 +320,19 @@ class TestDeleteCollection:
resp = client.delete("/library/api/collections/coll-missing")
assert resp.status_code == 404
+ def test_generic_error_returns_400(self):
+ app = _create_test_app()
+ svc = Mock()
+ svc.delete_collection.return_value = {
+ "deleted": False,
+ "error": "Cannot delete default collection",
+ }
+ with _authenticated_client(app, mock_coll_service=svc) as client:
+ resp = client.delete("/library/api/collections/coll-1")
+ assert resp.status_code == 400
+ data = resp.get_json()
+ assert data["success"] is False
+
# ---------------------------------------------------------------------------
# DELETE /library/api/collections/<id>/index
diff --git a/tests/research_library/routes/test_rag_routes.py b/tests/research_library/routes/test_rag_routes.py
index ae44333abe..060ea0cf9e 100644
--- a/tests/research_library/routes/test_rag_routes.py
+++ b/tests/research_library/routes/test_rag_routes.py
@@ -739,22 +739,6 @@ class TestRagCollectionRoutes:
)
assert response.status_code in [200, 302, 401, 403, 404, 500]
- def test_delete_collection_route(self):
- """Test /api/collections/<id> DELETE endpoint exists."""
- from flask import Flask
- from local_deep_research.research_library.routes.rag_routes import (
- rag_bp,
- )
-
- app = Flask(__name__)
- app.config["SECRET_KEY"] = "test-secret"
- app.register_blueprint(rag_bp)
- app.register_blueprint(auth_bp)
-
- with app.test_client() as client:
- response = client.delete("/library/api/collections/collection123")
- assert response.status_code in [200, 302, 401, 403, 404, 500]
-
class TestRagPageRoutes:
"""Tests for RAG page routes."""
diff --git a/tests/research_library/routes/test_rag_routes_coverage.py b/tests/research_library/routes/test_rag_routes_coverage.py
index 1c9a06ddfb..9446aa1132 100644
--- a/tests/research_library/routes/test_rag_routes_coverage.py
+++ b/tests/research_library/routes/test_rag_routes_coverage.py
@@ -1258,73 +1258,11 @@ class TestUpdateCollection:
# ---------------------------------------------------------------------------
-# Tests: DELETE /api/collections/<id>
+# Tests: DELETE /api/collections/<id> -- moved to delete_routes tests
+# (route removed from rag_routes.py, canonical endpoint in delete_routes.py)
# ---------------------------------------------------------------------------
-class TestDeleteCollection:
- def test_success(self, app):
- mock_service = Mock()
- mock_service.delete_collection.return_value = {
- "deleted": True,
- "chunks_deleted": 10,
- "orphaned_documents_deleted": 2,
- }
-
- with _auth_client(
- app,
- extra_patches=[
- patch(
- f"{_DEL_SVC}.CollectionDeletionService",
- return_value=mock_service,
- ),
- ],
- ) as (client, ctx):
- resp = client.delete("/library/api/collections/coll-1")
- assert resp.status_code == 200
- data = resp.get_json()
- assert data["success"] is True
- assert data["deleted_chunks"] == 10
-
- def test_not_found(self, app):
- mock_service = Mock()
- mock_service.delete_collection.return_value = {
- "deleted": False,
- "error": "Collection not found",
- }
-
- with _auth_client(
- app,
- extra_patches=[
- patch(
- f"{_DEL_SVC}.CollectionDeletionService",
- return_value=mock_service,
- ),
- ],
- ) as (client, ctx):
- resp = client.delete("/library/api/collections/coll-1")
- assert resp.status_code == 404
-
- def test_general_error(self, app):
- mock_service = Mock()
- mock_service.delete_collection.return_value = {
- "deleted": False,
- "error": "Cannot delete default",
- }
-
- with _auth_client(
- app,
- extra_patches=[
- patch(
- f"{_DEL_SVC}.CollectionDeletionService",
- return_value=mock_service,
- ),
- ],
- ) as (client, ctx):
- resp = client.delete("/library/api/collections/coll-1")
- assert resp.status_code == 400
-
-
# ---------------------------------------------------------------------------
# Tests: GET /api/collections/<id>/documents
# ---------------------------------------------------------------------------
diff --git a/tests/research_library/routes/test_rag_routes_deep_coverage.py b/tests/research_library/routes/test_rag_routes_deep_coverage.py
index e056645f72..de6715b8c0 100644
--- a/tests/research_library/routes/test_rag_routes_deep_coverage.py
+++ b/tests/research_library/routes/test_rag_routes_deep_coverage.py
@@ -610,58 +610,11 @@ class TestBackgroundIndexWorker:
# ---------------------------------------------------------------------------
-# delete_collection edge cases
+# delete_collection edge cases -- moved to delete_routes tests
+# (route removed from rag_routes.py, canonical endpoint in delete_routes.py)
# ---------------------------------------------------------------------------
-class TestDeleteCollectionEdgeCases:
- """Edge cases for delete_collection route."""
-
- def test_not_deleted_with_not_found_error(self, app):
- """Returns 404 when deletion result has 'not found' error."""
- mock_del_service = Mock()
- mock_del_service.delete_collection.return_value = {
- "deleted": False,
- "error": "Collection not found in database",
- }
-
- with _auth_client(
- app,
- extra_patches=[
- patch(
- f"{_DEL_SVC}.CollectionDeletionService",
- return_value=mock_del_service,
- ),
- ],
- ) as (client, ctx):
- resp = client.delete("/library/api/collections/coll-1")
- assert resp.status_code == 404
- data = resp.get_json()
- assert data["success"] is False
-
- def test_not_deleted_with_generic_error(self, app):
- """Returns 400 when deletion fails with non-'not found' error."""
- mock_del_service = Mock()
- mock_del_service.delete_collection.return_value = {
- "deleted": False,
- "error": "Cannot delete default collection",
- }
-
- with _auth_client(
- app,
- extra_patches=[
- patch(
- f"{_DEL_SVC}.CollectionDeletionService",
- return_value=mock_del_service,
- ),
- ],
- ) as (client, ctx):
- resp = client.delete("/library/api/collections/coll-1")
- assert resp.status_code == 400
- data = resp.get_json()
- assert data["success"] is False
-
-
# ---------------------------------------------------------------------------
# upload_to_collection: PDF storage and edge cases
# ---------------------------------------------------------------------------
diff --git a/tests/security/test_session_username_hardening.py b/tests/security/test_session_username_hardening.py
index b4be6d27e5..225d4715dc 100644
--- a/tests/security/test_session_username_hardening.py
+++ b/tests/security/test_session_username_hardening.py
@@ -437,7 +437,6 @@ class TestRAGRoutesSessionAccess:
cancel_indexing,
configure_rag,
create_collection,
- delete_collection,
get_collection_documents,
get_collections,
get_documents,
@@ -466,7 +465,6 @@ class TestRAGRoutesSessionAccess:
get_collections,
create_collection,
update_collection,
- delete_collection,
upload_to_collection,
get_collection_documents,
index_collection,