Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drive_mv in Shared Drive environment #377

Closed
bllittle opened this issue Oct 6, 2021 · 17 comments · Fixed by #379
Closed

drive_mv in Shared Drive environment #377

bllittle opened this issue Oct 6, 2021 · 17 comments · Fixed by #379

Comments

@bllittle
Copy link

bllittle commented Oct 6, 2021

I would like to move files to another folder when uploading a new version so people have a record of previous files to refer to. drive_mv() worked fine for this in April 2021. Now when I try the same code in the same environment (and I continue with the same rights on the folders), I get the following error:
Error: Client error: (403) Forbidden
A shared drive item must have exactly one parent.

  • domain: global
  • reason: teamDrivesParentLimit
  • message: A shared drive item must have exactly one parent.
    Run rlang::last_error() to see where the error occurred.
  mvFiles <- drive_mv(file=as_id(curLink),
  •                       path=archPath
    
  •                       )
    

I've also tried this with the overwrite = TRUE parameter, but the same result.
EDIT: Here is sample code:

for(ri in 163:length(recFilterSchools)){
  #    ri <- 3 # for testing
    curSchool <- recFilterSchools[ri]
    curFile <- paste0(fileInputPath,curSchool,".xlsx")
    fSave <- paste0(curSchool, fReName, fDate)
    fSchoolURLS <- google_Fldrs_Results %>% filter(SchoolNum==curSchool, FolderName==tList)
    fSchoolURLS_Arch <- google_Fldrs_Results %>% filter(SchoolNum==curSchool, ParentFolder==tList, FolderName=='Archive')
    targetDir <- fSchoolURLS$FileURL
    targetArch <- fSchoolURLS_Arch$FileURL
    parentID <- fSchoolURLS$LocationID
    schID <- fSchoolURLS$schID
    curMslRow <- msl_Results %>%
      filter(SCHOOL_NUMBER==curSchool)
    
    curSchoolName <- curMslRow$School
    drID <- drive_get(targetDir, verbose = TRUE)
    curFolderContents <- drive_ls(targetDir, 
                                  pattern= tList,
                                  type='spreadsheet')
    #     typeof(curFolderContents)
    #      fmRows <- nrow(curFolderContents)
    fmRows <- nrow(curFolderContents)
    if (fmRows>0){
      for (fm in 1:nrow(curFolderContents)){
        #        fm <-1
        mvFiles <- drive_mv(file=as_id(curFolderContents$id[fm]),
                            path=targetArch
                            ,name= curFolderContents$name[fm])
        drResources <- mvFiles$drive_resource[[1]]
        OutUploadedDF <- rbind(OutUploadedDF, data.frame(stringsAsFactors = FALSE,
                                                         FileID = mvFiles$id,
                                                         FileName = mvFiles$name,
                                                         FilePath = drResources$webViewLink,
                                                         FileParent = parentID,
                                                         FileType = drResources$mimeType,
                                                         DateUploaded  = format(Sys.time(),'%m/%d/%Y'),
                                                         schID = schID))
        
        
      }    
    }
  #more code below to upload new file to folder 
}

```thanks
@jennybc
Copy link
Member

jennybc commented Oct 7, 2021

I would need to see a code snippet that allows me to create the situation and reproduce this. I can't troubleshoot based on the above.

@bllittle
Copy link
Author

Hi @jennybc,

I updated with more code -- any thoughts?

Thanks,
Bruce

@Falnesio
Copy link
Contributor

Presenting same problem moving newly created test file into test folder in shared drive through drive_mv()

@jennybc
Copy link
Member

jennybc commented Oct 20, 2021

I haven't delved into this deeply, but I will quickly share that I had a recent bulk file moving task involving a folder on a shared drive and there are definitely limits re: who can do such moves. I actually had to get our Google Workspace admin to elevate my privileges, watch me work on a Zoom call while sharing my screen, then I was de-privileged afterwards.

So my hunch, given my experience and that there's two of you now, is that what you're trying to do may actually not be allowed. Versus being a flaw in the googledrive package.

I could be wrong, but just wanted to mention this, so you can continue to troubleshoot or workaround, before I have time to engage more deeply with this issue.

@bllittle
Copy link
Author

bllittle commented Oct 20, 2021 via email

@Falnesio
Copy link
Contributor

Falnesio commented Oct 26, 2021

Thank you for the quick reply, and sorry for responding so late.

I am admin, but I checked to see if I have used the wrong account, and it was not the case. I got this:

Client error: (403) Forbidden
A shared drive item must have exactly one parent.

  • domain: global
  • reason: teamDrivesParentLimit
  • message: A shared drive item must have exactly one parent.
    Run rlang::last_error() to see where the error occurred.

@jennybc
Copy link
Member

jennybc commented Oct 26, 2021

Yeah I think I know what the problem is. I'm pretty sure it's a relatively easy fix.

@jennybc
Copy link
Member

jennybc commented Oct 29, 2021

I've been able to replicate the problem and fix it with #379. I remember initially being pleasantly surprised that I could just add a parent folder, w/o removing the previous one. As we've all experienced, that did work at one point in time. But it no longer does and, frankly, the current behaviour was always sort of implied by the docs. So now I add and remove parent(s) in one atomic operation.

I need to test this solution a bit more, before I merge it, but if anyone here wants to independently verify that this is basically the fix, feel free to install from that PR and report back.

Here are some ways to install googledrive from that PR:

install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/")
pak::pkg_install("tidyverse/googledrive#379")

# or
devtools::install_github("tidyverse/googledrive#379")

@bllittle
Copy link
Author

bllittle commented Oct 29, 2021 via email

@Falnesio
Copy link
Contributor

The solution has worked here. Thank you very much!

@jennybc
Copy link
Member

jennybc commented Oct 29, 2021

More background, mostly for myself: the existing logic seems to work in a user's My Drive. But you do really have to remove parent +add parent if the file in question lives on a shared drive. This problem is currently only affecting people moving files around on a shared drive.

@bllittle
Copy link
Author

bllittle commented Mar 7, 2022 via email

@bllittle
Copy link
Author

bllittle commented Mar 7, 2022 via email

@deschen1
Copy link

Not sure if entirely related this bug, but I have the same error/issue and it still doesn't work, see my SO post: https://stackoverflow.com/questions/73750125/trying-to-move-a-google-drive-file-with-googledrive-package-results-in-403-error

@jennybc
Copy link
Member

jennybc commented Sep 16, 2022

@deschen1 Apparently I haven't released googledrive since I made this fix. This appears to the be only (substantive) change made since the last release.

So for now, you need to use the dev version.

@deschen1
Copy link

Ah ok, that probably explains it.

Since we are here, do you have any idea/plan on next releases? I understand the desire to avoid the overhead of publishing a new release just for a supposedly minor bug fix, but since it's several people now making it so far to respond on the dev page of the package, I feel there's indeed an audience for an updated version. ;-)

@jennybc
Copy link
Member

jennybc commented Sep 17, 2022

I have to release gargle soon for other reasons, so then it would make sense to release googledrive (which currently depends on dev gargle). I'll put this on my near-term todo list.

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 a pull request may close this issue.

4 participants