mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-12-05 18:59:51 +00:00
Fix: return 404 instead of 500 when a document is trashed during its own update
DocumentViewSet.update saves the change and then re-reads the document through the default manager, which excludes soft deleted rows. A concurrent request that moved the document to the trash in between made that read raise DoesNotExist, so the client got a 500 for a document that no longer exists. Raise Http404 instead, the same answer get_object() gives when the document is already trashed at the start of the request. The committed change is kept. Found while hammering the API with concurrent PATCH and delete requests.
This commit is contained in:
1 parent
8d866bbf32
commit
c8ce651111
2 files changed
+49
-1
No files matched your search
@@ -1327,7 +1327,11 @@ class DocumentViewSet(
|
||||
)
|
||||
content_doc.save(update_fields=["content", "modified"])
|
||||
|
||||
refreshed_doc = self.get_queryset().get(pk=root_doc.pk)
|
||||
try:
|
||||
refreshed_doc = self.get_queryset().get(pk=root_doc.pk)
|
||||
except Document.DoesNotExist:
|
||||
# Trashed by a concurrent request after our write committed
|
||||
raise Http404
|
||||
response_data = self.get_serializer(refreshed_doc).data
|
||||
if "version" in request.query_params and "content" in response_data:
|
||||
response_data["content"] = content_doc.content
|
||||
|
||||
Reference in new issue
Block a user