Fix bug preventing deleting collections with no crawls (#912)

This commit is contained in:
Tessa Walsh 2023-06-08 14:28:30 -04:00 committed by GitHub
parent 9707fb55e4
commit e10b7093c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -875,12 +875,10 @@ class CrawlOps:
async def remove_collection_from_all_crawls(self, collection_id: uuid.UUID):
"""Remove collection id from all crawls it's currently in."""
result = await self.crawls.update_many(
await self.crawls.update_many(
{"collections": collection_id},
{"$pull": {"collections": collection_id}},
)
if result.modified_count < 1:
raise HTTPException(status_code=404, detail="crawls_not_found")
# ============================================================================

View File

@ -394,3 +394,23 @@ def test_delete_collection(crawler_auth_headers, default_org_id, crawler_crawl_i
headers=crawler_auth_headers,
)
assert _second_coll_id not in r.json()["collections"]
# Make a new empty (no crawls) collection and delete it
r = requests.post(
f"{API_PREFIX}/orgs/{default_org_id}/collections",
headers=crawler_auth_headers,
json={
"name": "To delete",
"description": "Deleting a collection with no crawls should work.",
},
)
assert r.status_code == 200
data = r.json()
coll_id = data["added"]["id"]
r = requests.delete(
f"{API_PREFIX}/orgs/{default_org_id}/collections/{coll_id}",
headers=crawler_auth_headers,
)
assert r.status_code == 200
assert r.json()["success"]