Skip to content

fix: dispatch dataset cleanup when doc_form is missing#38579

Open
Zhengcy05 wants to merge 2 commits into
langgenius:mainfrom
Zhengcy05:fix/dataset-delete-cleanup-doc-form
Open

fix: dispatch dataset cleanup when doc_form is missing#38579
Zhengcy05 wants to merge 2 commits into
langgenius:mainfrom
Zhengcy05:fix/dataset-delete-cleanup-doc-form

Conversation

@Zhengcy05

Copy link
Copy Markdown

Important

  1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md)
  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

Fixes #38537

This PR fixes the dataset deletion path for migrated datasets whose doc_form is missing.

The delete event handler previously returned early when either doc_form or indexing_technique was empty, which meant clean_dataset_task was never dispatched for some migrated datasets. However, clean_dataset_task already handles an empty doc_form by falling back to PARAGRAPH_INDEX, so the handler was blocking a case the downstream cleanup path could already recover from.

This change keeps the existing safeguard for missing indexing_technique, but stops skipping cleanup when only doc_form is missing.

Changes included in this PR:

  • narrow the dataset deletion guard in clean_when_dataset_deleted.py
  • update the existing integration test expectation for the doc_form=None case
  • add a focused unit test for the event handler dispatch behavior

Local verification:

  • uv run --project api --group dev pytest api/tests/unit_tests/events/event_handlers/test_clean_when_dataset_deleted.py
  • uv run --project api --group dev ruff check api/events/event_handlers/clean_when_dataset_deleted.py api/tests/unit_tests/events/event_handlers/test_clean_when_dataset_deleted.py api/tests/test_containers_integration_tests/services/test_dataset_service_delete_dataset.py

Screenshots

Before After
N/A N/A

Checklist

  • This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs)
  • 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 make lint && make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jul 9, 2026
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-07-09 04:00:56.813213340 +0000
+++ /tmp/pyrefly_pr.txt	2026-07-09 04:00:48.392145449 +0000
@@ -1,3 +1,5 @@
+ERROR Argument `str | None` is not assignable to parameter `doc_form` with type `str` in function `celery.app.task.Task.delay` [bad-argument-type]
+  --> events/event_handlers/clean_when_dataset_deleted.py:20:9
 ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset` with type `Dataset` in function `dify_vdb_alibabacloud_mysql.alibabacloud_mysql_vector.AlibabaCloudMySQLVectorFactory.init_vector` [bad-argument-type]
   --> providers/vdb/vdb-alibabacloud-mysql/tests/unit_tests/test_alibabacloud_mysql_factory.py:42:38
 ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset` with type `Dataset` in function `dify_vdb_alibabacloud_mysql.alibabacloud_mysql_vector.AlibabaCloudMySQLVectorFactory.init_vector` [bad-argument-type]

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 52.59% 52.59% 0.00%
Strict coverage 52.11% 52.11% 0.00%
Typed symbols 32,538 32,538 0
Untyped symbols 29,605 29,605 0
Modules 2982 2982 0

@fatelei

fatelei commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

style check failed

@Zhengcy05 Zhengcy05 requested a review from JohnJyong as a code owner July 9, 2026 05:45
@Zhengcy05

Copy link
Copy Markdown
Author

style check failed

Thx, I've fixed it.

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

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deleting a dataset leaves an orphaned vector collection when doc_form or indexing_technique is empty (vector DB never cleaned up)

2 participants