Compare commits

...
Author SHA1 Message Date
shamoonandGitHub 05917a04aa Fix: immediately re-add doc to index after trash restore (#13818) 2026-08-27 12:19:31 -07:00
2 changed files with 38 additions and 1 deletions
+30
View File
@@ -93,6 +93,36 @@ class TestDocumentSearchApi(DirectoriesMixin, APITestCase):
self.assertEqual(response.data["count"], 0) self.assertEqual(response.data["count"], 0)
self.assertEqual(len(results), 0) self.assertEqual(len(results), 0)
def test_search_after_restore_from_trash(self) -> None:
"""
GIVEN:
- Indexed document that was moved to the trash
WHEN:
- The document is restored from the trash
THEN:
- The document is searchable again without a reindex
"""
doc = Document.objects.create(
title="invoice",
content="the thing i bought at a shop and paid with bank account",
checksum="A",
pk=1,
)
get_backend().add_or_update(doc)
self.assertEqual(self.client.get("/api/documents/?query=shop").data["count"], 1)
self.client.delete(f"/api/documents/{doc.pk}/")
self.assertEqual(self.client.get("/api/documents/?query=shop").data["count"], 0)
response = self.client.post(
"/api/trash/",
{"action": "restore", "documents": [doc.pk]},
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(self.client.get("/api/documents/?query=shop").data["count"], 1)
def test_simple_text_search(self) -> None: def test_simple_text_search(self) -> None:
tagged = Tag.objects.create(name="invoice") tagged = Tag.objects.create(name="invoice")
matching_doc = Document.objects.create( matching_doc = Document.objects.create(
+8 -1
View File
@@ -5432,8 +5432,15 @@ class TrashView(ListModelMixin, PassUserMixin):
return HttpResponseForbidden("Insufficient permissions") return HttpResponseForbidden("Insufficient permissions")
action = serializer.validated_data.get("action") action = serializer.validated_data.get("action")
if action == "restore": if action == "restore":
for doc in Document.deleted_objects.filter(id__in=doc_ids).all(): restored = list(Document.deleted_objects.filter(id__in=doc_ids))
for doc in restored:
doc.restore(strict=False) doc.restore(strict=False)
if restored:
from documents.search import get_backend
with get_backend().batch_update() as batch:
for doc in restored:
batch.add_or_update(doc)
elif action == "empty": elif action == "empty":
if doc_ids is None: if doc_ids is None:
doc_ids = [doc.id for doc in docs] doc_ids = [doc.id for doc in docs]