From bffaebd35112978ea38bbbedc52dd27099354013 Mon Sep 17 00:00:00 2001 From: Abhishek Pandey Date: Thu, 10 Aug 2023 10:33:38 +0530 Subject: [PATCH] Skip item if metadata fetch fails with 404 (#4001) GET permissions fails if the item doesn't exist. We are hitting sanity test failures due to a race condition between test run & purge scripts. `getting item metadata: getting item metadata: error status code received from the API: Item not found:` Fix here is to ignore GET permissions failure if it returns not found. This is safe to do here, since the graph call for permissions [looks up the item by id](https://github.com/alcionai/corso/blob/main/src/pkg/services/m365/api/drive.go#L254C17-L254C17), and not the permissions by id. Hence, we can safely assume that the item that this permission is tied to has been deleted. --- #### Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No #### Type of change - [ ] :sunflower: Feature - [x] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Supportability/Tests - [ ] :computer: CI/Deployment - [ ] :broom: Tech Debt/Cleanup #### Issue(s) * https://github.com/alcionai/corso/issues/3998 #### Test Plan - [x] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/m365/onedrive/collection.go | 8 ++++++-- src/pkg/services/m365/api/drive.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/internal/m365/onedrive/collection.go b/src/internal/m365/onedrive/collection.go index e393554ab..377152e48 100644 --- a/src/internal/m365/onedrive/collection.go +++ b/src/internal/m365/onedrive/collection.go @@ -512,10 +512,14 @@ func (oc *Collection) populateDriveItem( metaSuffix = metadata.DirMetaFileSuffix } - // Fetch metadata for the file + // Fetch metadata for the item itemMeta, itemMetaSize, err = downloadItemMeta(ctx, oc.handler, oc.driveID, item) if err != nil { - errs.AddRecoverable(ctx, clues.Wrap(err, "getting item metadata").Label(fault.LabelForceNoBackupCreation)) + // Skip deleted items + if !clues.HasLabel(err, graph.LabelStatus(http.StatusNotFound)) && !graph.IsErrDeletedInFlight(err) { + errs.AddRecoverable(ctx, clues.Wrap(err, "getting item metadata").Label(fault.LabelForceNoBackupCreation)) + } + return } diff --git a/src/pkg/services/m365/api/drive.go b/src/pkg/services/m365/api/drive.go index 85bc0a8ca..e40d7497a 100644 --- a/src/pkg/services/m365/api/drive.go +++ b/src/pkg/services/m365/api/drive.go @@ -255,7 +255,7 @@ func (c Drives) GetItemPermission( Permissions(). Get(ctx, nil) if err != nil { - return nil, graph.Wrap(ctx, err, "getting item metadata").With("item_id", itemID) + return nil, graph.Wrap(ctx, err, "getting item permission").With("item_id", itemID) } return perm, nil