Skip to content

fix(dataset): clean multimodal attachments during reindex - #41999

Merged
fatelei merged 1 commit into
langgenius:mainfrom
CoralGarden52:fix/reindex-multimodal-attachment-cleanup
Sep 9, 2026
Merged

fatelei merged 1 commit into
langgenius:mainfrom
CoralGarden52:fix/reindex-multimodal-attachment-cleanup

Conversation

@CoralGarden52

Copy link
Copy Markdown
Contributor

Summary

  • delete the replaced document segment attachment bindings during multimodal re-indexing
  • remove attachment vectors and UploadFile rows only after confirming that no bindings still reference them, preserving shared attachments
  • delete storage objects after the database commit with per-key error handling

This follows the attachment lifecycle and orphan-check behavior established by #41400 while keeping this bug fix scoped to the re-index path.

Fixes #41994

Screenshots

Not applicable. This is a backend cleanup task fix.

Testing

  • api/.venv/bin/pytest -q api/tests/unit_tests/tasks/test_document_indexing_update_task.py (16 passed)
  • api/.venv/bin/pytest -q api/tests/unit_tests/tasks/test_document_indexing_update_task.py api/tests/unit_tests/tasks/test_segment_index_cleanup_tasks.py api/tests/unit_tests/tasks/test_batch_clean_document_task.py api/tests/unit_tests/tasks/test_clean_document_task.py (28 passed)
  • api/.venv/bin/ruff format --check api/tasks/document_indexing_update_task.py api/tests/unit_tests/tasks/test_document_indexing_update_task.py
  • api/.venv/bin/ruff check api/tasks/document_indexing_update_task.py api/tests/unit_tests/tasks/test_document_indexing_update_task.py
  • api/.venv/bin/pyrefly check api/tasks/document_indexing_update_task.py

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 does not apply to typos!)
  • I added regression coverage for orphaned and shared attachments, plus storage deletion failures.
  • I updated the documentation accordingly. (No documentation change is required.)
  • I ran make lint && make type-check (backend). Targeted Ruff and Pyrefly checks passed; full Mypy is blocked locally by missing optional provider packages.

From Codex

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 63.91% 63.92% +0.01%
Strict coverage 63.52% 63.53% +0.01%
Typed symbols 45,593 45,607 +14
Untyped symbols 25,904 25,903 -1
Modules 3384 3384 0

@fatelei
fatelei added this pull request to the merge queue Sep 9, 2026
Merged via the queue into langgenius:main with commit 89df7a6 Sep 9, 2026
45 checks passed
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: Re-indexing a multimodal document leaves stale attachment bindings and files

2 participants