[GH-ISSUE #2398] [BUG] Folder document count includes soft-deleted documents (deletedAt not filtered) #675

Closed
opened 2026-02-26 18:48:00 +03:00 by kerem · 1 comment
Owner

Originally created by @maviei on GitHub (Jan 18, 2026).
Original GitHub issue: https://github.com/documenso/documenso/issues/2398

Bug Description

Folder cards display incorrect document counts because the count query includes soft-deleted documents (documents where
deletedAt IS NOT NULL).

Steps to Reproduce

  1. Create a folder
  2. Add documents to the folder
  3. Complete the documents (sign them)
  4. Delete the completed documents from the UI
  5. Observe that the folder still shows the document count

Expected Behavior

The folder should show 0 documents after all documents are deleted.

Actual Behavior

The folder continues showing the original document count (e.g., "6 documents") even though all documents were soft-deleted.

Technical Analysis

Root Cause: In packages/lib/server-only/folder/find-folders-internal.ts, the document count query does not filter by
deletedAt:

prisma.envelope.count({
  where: {
    type: EnvelopeType.DOCUMENT,
    folderId: folder.id,
    // ⚠️ Missing: deletedAt: null
  }
})

Suggested Fix

Add deletedAt: null filter to the count query:

prisma.envelope.count({
  where: {
    type: EnvelopeType.DOCUMENT,
    folderId: folder.id,
    deletedAt: null,  // Add this filter
  }
})

Environment

- Documenso Version: v2.3.1
- Deployment: Docker (self-hosted)
- Database: PostgreSQL 15
Originally created by @maviei on GitHub (Jan 18, 2026). Original GitHub issue: https://github.com/documenso/documenso/issues/2398 ## Bug Description Folder cards display incorrect document counts because the count query includes soft-deleted documents (documents where `deletedAt IS NOT NULL`). ## Steps to Reproduce 1. Create a folder 2. Add documents to the folder 3. Complete the documents (sign them) 4. Delete the completed documents from the UI 5. Observe that the folder still shows the document count ## Expected Behavior The folder should show `0 documents` after all documents are deleted. ## Actual Behavior The folder continues showing the original document count (e.g., "6 documents") even though all documents were soft-deleted. ## Technical Analysis **Root Cause**: In `packages/lib/server-only/folder/find-folders-internal.ts`, the document count query does not filter by `deletedAt`: ```typescript prisma.envelope.count({ where: { type: EnvelopeType.DOCUMENT, folderId: folder.id, // ⚠️ Missing: deletedAt: null } }) Suggested Fix Add deletedAt: null filter to the count query: prisma.envelope.count({ where: { type: EnvelopeType.DOCUMENT, folderId: folder.id, deletedAt: null, // Add this filter } }) Environment - Documenso Version: v2.3.1 - Deployment: Docker (self-hosted) - Database: PostgreSQL 15
kerem 2026-02-26 18:48:00 +03:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 18, 2026):

Thank you for opening your first issue and for being a part of the open signing revolution!

One of our team members will review it and get back to you as soon as it possible 💚

Meanwhile, please feel free to hop into our community in Discord

<!-- gh-comment-id:3765707644 --> @github-actions[bot] commented on GitHub (Jan 18, 2026): Thank you for opening your first issue and for being a part of the open signing revolution! <br /> One of our team members will review it and get back to you as soon as it possible 💚 <br /> Meanwhile, please feel free to hop into our community in [Discord](https://documen.so/discord)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/documenso#675
No description provided.