Skip to content

fix delete conversations via Api and delete conversations from db as well#23591

Merged
laipz8200 merged 27 commits intolanggenius:mainfrom
jubinsoni:22868-fix-delete-conversations
Aug 25, 2025
Merged

fix delete conversations via Api and delete conversations from db as well#23591
laipz8200 merged 27 commits intolanggenius:mainfrom
jubinsoni:22868-fix-delete-conversations

Conversation

@jubinsoni
Copy link
Copy Markdown
Contributor

@jubinsoni jubinsoni commented Aug 7, 2025

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Fix #22868
close #22445

Screenshots

Before After
... ...

before
eventough we have deleted conversation, it still used to show in log pages and entry is also there in db

Screenshot 2025-08-08 at 1 41 58 AM Screenshot 2025-08-08 at 1 42 31 AM Screenshot 2025-08-08 at 1 49 37 AM

after
if we delete conversation, it will not show in log page and entry in db will also be deleted
Screenshot 2025-08-08 at 2 25 31 AM
Screenshot 2025-08-08 at 2 26 07 AM
Screenshot 2025-08-08 at 2 26 36 AM

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 7, 2025
@crazywoola crazywoola requested a review from Copilot August 8, 2025 01:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the conversation deletion functionality by implementing proper database cleanup when conversations are deleted via the API. Previously, conversations were only marked as deleted without removing related data or entries from the database.

  • Replaces soft deletion with hard deletion for conversations and all related entities
  • Adds a new method get_conversation_for_deletion to handle deletion-specific conversation retrieval
  • Updates console controllers to use the centralized conversation service for deletion operations

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
api/services/conversation_service.py Implements hard deletion of conversations with cascade deletion of related entities and adds deletion-specific conversation retrieval
api/controllers/console/app/conversation.py Updates both completion and chat conversation controllers to use centralized deletion service and filters out deleted conversations from listings

@crazywoola
Copy link
Copy Markdown
Member

@jubinsoni Sorry, try to fix this, but it failed :) Please resolve it again thanks :)

crazywoola
crazywoola previously approved these changes Aug 8, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 8, 2025
@jubinsoni
Copy link
Copy Markdown
Contributor Author

@crazywoola
I tried couple of time to fix the for loop to delete records, some how pytest kept giving error that the table migh not have conversation_id

so to fix that I have unwrapped the for loop

also I have closed the session in the finally block so that connection goes back to connection pool

@crazywoola crazywoola requested a review from laipz8200 August 8, 2025 06:50
@dosubot dosubot bot removed the lgtm This PR has been approved by a maintainer label Aug 8, 2025
@jubinsoni
Copy link
Copy Markdown
Contributor Author

sample celery logs

Screenshot 2025-08-09 at 12 01 17 AM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 25, 2025
@laipz8200 laipz8200 merged commit 3aedc13 into langgenius:main Aug 25, 2025
7 checks passed
@lyzno1 lyzno1 mentioned this pull request Aug 25, 2025
qiqizjl pushed a commit to qiqizjl/dify that referenced this pull request Aug 27, 2025
…well (langgenius#23591)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: crazywoola <427733928@qq.com>
Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
HarryReidx pushed a commit to HarryReidx/dify that referenced this pull request Sep 1, 2025
…well (langgenius#23591)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: crazywoola <427733928@qq.com>
Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
(cherry picked from commit 3aedc13)
@dosubot dosubot bot mentioned this pull request Sep 1, 2025
6 tasks
@LinzhouWang1
Copy link
Copy Markdown

我在这里有个疑问?为什么要将软删除改为硬删除?软删除不应该是一个应用通用的标准么?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot Delete Conversations via REST API

5 participants