Skip to content

fix(folder): make empty-trash deletion idempotent - #8934

Open
SulimanAbdulrazzaq wants to merge 1 commit into
AppFlowy-IO:mainfrom
SulimanAbdulrazzaq:fix/8921-idempotent-trash-delete
Open

fix(folder): make empty-trash deletion idempotent#8934
SulimanAbdulrazzaq wants to merge 1 commit into
AppFlowy-IO:mainfrom
SulimanAbdulrazzaq:fix/8921-idempotent-trash-delete

Conversation

@SulimanAbdulrazzaq

@SulimanAbdulrazzaq SulimanAbdulrazzaq commented Aug 9, 2026

Copy link
Copy Markdown

Feature Preview

N/A — bug fix.

Fixes #8921

Emptying the trash now treats an already-missing backing collab as a successful deletion. This removes stale database-view trash entries while still propagating other deletion errors.

PR Checklist

  • My code adheres to AppFlowy's Conventions
  • I've listed at least one issue that this PR fixes in the description above.
  • I've added tests to validate changes in this PR.
  • All existing tests are passing (blocked locally by unavailable git dependencies).

Validation

  • rustfmt --edition 2024 --check frontend/rust-lib/flowy-folder/src/manager.rs passed.
  • cargo test -p flowy-folder --lib could not complete locally because Cargo could not fetch all git/crates.io dependencies within the available environment.

Summary by Sourcery

Make empty-trash deletion idempotent by treating missing backing collab data as a successful delete.

Bug Fixes:

  • Ensure emptying the trash removes stale database-view trash entries even when their backing collab has already been deleted, while still surfacing non-RecordNotFound errors.

Tests:

  • Add unit tests to verify that RecordNotFound errors from view deletion are treated as success and that other error types are propagated.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @SulimanAbdulrazzaq, your pull request is larger than the review limit of 150000 diff characters

@sourcery-ai

sourcery-ai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Makes empty-trash operations idempotent by treating missing backing collab data as a successful delete, and adds a small helper and tests to enforce this behavior in the folder manager trash deletion flow.

Sequence diagram for idempotent empty-trash deletion

sequenceDiagram
  participant FolderManager
  participant Folder
  participant FolderOperationHandler

  FolderManager->>Folder: get_my_trash_info()
  loop each TrashInfo.id
    FolderManager->>FolderManager: delete_trash(id)
    FolderManager->>Folder: delete_trash_view_ids(id)
    FolderManager->>Folder: delete_views(id)
    FolderManager->>FolderOperationHandler: delete_view(view_uuid)
    FolderOperationHandler-->>FolderManager: Result
    FolderManager->>FolderManager: ignore_missing_view_error(Result)
    alt [error.is_record_not_found()]
      FolderManager-->>FolderManager: treat as Ok(())
    else [other error]
      FolderManager-->>FolderManager: propagate Err(error)
    end
  end
Loading

File-Level Changes

Change Details Files
Make permanent trash deletion treat missing backing collab as a successful, idempotent delete instead of an error.
  • Wrap handler.delete_view in a helper that converts RecordNotFound errors into Ok(()) when deleting trash views.
  • Keep removing the trash entry and view from the Folder before invoking the handler, so stale DB-view trash rows are still cleaned up.
  • Preserve propagation of all non-RecordNotFound errors from delete_view.
frontend/rust-lib/flowy-folder/src/manager.rs
Introduce a reusable helper for ignoring missing-view errors and add unit tests to lock in the behavior.
  • Add ignore_missing_view_error(FlowyResult<()>) -> FlowyResult<()> that maps RecordNotFound to success and leaves other results untouched.
  • Document the race condition between trash cleanup and backing collab deletion in the helper’s doc comment.
  • Add tests verifying that record_not_found is treated as success and other errors retain their ErrorCode::Internal.
frontend/rust-lib/flowy-folder/src/manager.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#8921 Make empty-trash deletion for database views idempotent so that missing backing database collabs are treated as successful deletions and stale trash entries are removed.
#8921 Ensure deleting individual trash items for database views succeeds even when their backing database collabs are already deleted, so those items no longer remain stuck in trash.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@SulimanAbdulrazzaq
SulimanAbdulrazzaq force-pushed the fix/8921-idempotent-trash-delete branch from 4ef7148 to 855fab3 Compare August 9, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Empty trash fails silently for database views — items permanently stuck in trash (0.13.0)

2 participants