From 1aa951132c859ea6e8598c7bfe72f8a0ce64c1bd Mon Sep 17 00:00:00 2001 From: Tessa Walsh Date: Wed, 30 Aug 2023 18:16:21 -0400 Subject: [PATCH] Fix unsetting all collections via PATCH update (#1126) --- backend/btrixcloud/basecrawls.py | 2 +- backend/test/test_uploads.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/backend/btrixcloud/basecrawls.py b/backend/btrixcloud/basecrawls.py index c3e3a674..dd8d576d 100644 --- a/backend/btrixcloud/basecrawls.py +++ b/backend/btrixcloud/basecrawls.py @@ -167,7 +167,7 @@ class BaseCrawlOps: # Update collections then unset from update_values # We handle these separately due to updates required for collection changes collection_ids = update_values.get("collectionIds") - if collection_ids: + if collection_ids is not None: await self._update_crawl_collections(crawl_id, org, collection_ids) update_values.pop("collectionIds", None) diff --git a/backend/test/test_uploads.py b/backend/test/test_uploads.py index 7e064f05..9f668e4f 100644 --- a/backend/test/test_uploads.py +++ b/backend/test/test_uploads.py @@ -810,6 +810,31 @@ def test_update_upload_metadata_all_crawls(admin_auth_headers, default_org_id): assert data["name"] == UPDATED_NAME assert data["collectionIds"] == UPDATED_COLLECTION_IDS + # Submit patch request to set collections to empty list + UPDATED_COLLECTION_IDS = [] + r = requests.patch( + f"{API_PREFIX}/orgs/{default_org_id}/all-crawls/{upload_id}", + headers=admin_auth_headers, + json={ + "collectionIds": UPDATED_COLLECTION_IDS, + }, + ) + assert r.status_code == 200 + data = r.json() + assert data["updated"] + + # Verify update was successful + r = requests.get( + f"{API_PREFIX}/orgs/{default_org_id}/all-crawls/{upload_id}", + headers=admin_auth_headers, + ) + assert r.status_code == 200 + data = r.json() + assert sorted(data["tags"]) == sorted(UPDATED_TAGS) + assert data["description"] == UPDATED_DESC + assert data["name"] == UPDATED_NAME + assert data["collectionIds"] == [] + def test_delete_form_upload_from_all_crawls(admin_auth_headers, default_org_id): r = requests.post(