Skip to content

fix: close SQLite connection before removing collection directory on delete#1148

Open
veeceey wants to merge 2 commits intoqdrant:devfrom
veeceey:fix/issue-1067-delete-collection-windows
Open

fix: close SQLite connection before removing collection directory on delete#1148
veeceey wants to merge 2 commits intoqdrant:devfrom
veeceey:fix/issue-1067-delete-collection-windows

Conversation

@veeceey
Copy link
Copy Markdown

@veeceey veeceey commented Feb 7, 2026

Summary

  • Fixed delete_collection in local mode not explicitly closing the SQLite connection before attempting to remove the collection directory with shutil.rmtree
  • On Windows, this left the database file locked, causing shutil.rmtree to silently fail (due to ignore_errors=True), leaving the storage.sqlite file on disk
  • The fix calls collection.close() before directory removal in both sync (QdrantLocal) and async (AsyncQdrantLocal) implementations, matching the pattern already used in QdrantLocal.close()
  • Added regression test that verifies storage files are properly removed after delete_collection

Root Cause

In delete_collection, the LocalCollection was popped from the dict and del was called on the variable. However, del in Python only decrements the reference count and does not guarantee the SQLite connection is closed. On Windows, the open connection holds a file lock on storage.sqlite, preventing shutil.rmtree from deleting it.

Test Plan

  • Added test_delete_collection_removes_storage_files to verify that storage files are properly removed after deletion
  • All existing test_local_persistence.py tests pass
  • All existing test_in_memory.py tests pass
  • test_async_qdrant_client_local passes

Fixes #1067

…delete

In delete_collection, the LocalCollection was popped from the collections dict and its reference deleted, but the SQLite connection was never explicitly closed. On Windows, this leaves the database file locked, preventing shutil.rmtree from removing it. The fix calls close() before directory removal, matching the pattern used in QdrantLocal.close().

Fixes qdrant#1067
@netlify
Copy link
Copy Markdown

netlify bot commented Feb 7, 2026

Deploy Preview for poetic-froyo-8baba7 ready!

Name Link
🔨 Latest commit c3cdccb
🔍 Latest deploy log https://app.netlify.com/projects/poetic-froyo-8baba7/deploys/69879810f8d5ab0007cbd2be
😎 Deploy Preview https://deploy-preview-1148--poetic-froyo-8baba7.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 7, 2026

📝 Walkthrough

Walkthrough

The PR updates local Qdrant client code to close collection resources when deleting a collection in both synchronous and asynchronous implementations (close if the collection existed before removal). It reformats an assertion in upload_collection that checks consistent vector lengths (no logic change). A new test, test_delete_collection_removes_storage_files, is added to verify that the collection directory and its storage.sqlite file are removed after delete_collection.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and specifically describes the main fix: closing the SQLite connection before removing the collection directory on delete.
Description check ✅ Passed The PR description is comprehensive and directly related to the changes, explaining the root cause, the fix applied, and the test plan.
Linked Issues check ✅ Passed The PR fully addresses the requirements from issue #1067: it explicitly closes SQLite connections before directory removal [#1067], ensures storage files are removed on Windows [#1067], and adds regression tests [#1067].
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the delete_collection issue: closing connections in sync/async implementations, assertion reformatting for clarity, and adding relevant regression tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@veeceey
Copy link
Copy Markdown
Author

veeceey commented Feb 7, 2026

Addressed the CodeRabbit nitpick: added client.close() at the end of test_delete_collection_removes_storage_files to ensure the client is explicitly closed after assertions, preventing potential flaky failures on Windows from file lock races during temp directory cleanup. Fixed in c3cdccb.

@veeceey
Copy link
Copy Markdown
Author

veeceey commented Feb 8, 2026

All checks passing, ready for maintainer review

@veeceey
Copy link
Copy Markdown
Author

veeceey commented Feb 10, 2026

Hi maintainers, friendly ping on this PR. It's been open a couple of days now and all checks are passing. Would appreciate it whenever you get a chance to review. Thank you for your time!

@veeceey
Copy link
Copy Markdown
Author

veeceey commented Feb 20, 2026

Friendly bump — all checks are passing and the CodeRabbit feedback has been addressed. Would appreciate a maintainer review when you get a chance. Thanks!

@veeceey
Copy link
Copy Markdown
Author

veeceey commented Apr 9, 2026

checking in on this - happy to make any changes if needed

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.

1 participant